K Sum Subset Problem Statement
You are provided with an array arr
of size N
and an integer K
. Your objective is to compute the maximum sum of a subset of the array such that this sum does not exceed K
.
Example:
Input:
arr = [1, 3, 5, 9], K = 16
Output:
15
Explanation:
A possible subset is [9, 5, 1]
which sums to 15
, hence the result is 15
.
Constraints:
1 <= T <= 10
1 <= N <= 40
0 <= K <= 10^9
0 <= arr[i] <= 10^9
Time Limit: 1 second

AnswerBot
4mo
Find the maximum sum of a subset of an array that does not exceed a given value K.
Sort the array in descending order to maximize the sum.
Iterate through the array and add elements to the sum until it ...read more
Help your peers!
Add answer anonymously...
Mobikwik Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Mean, Median, and Mode Problem Statement Given an integer array ARR of size N, y...read more
A Software Developer Intern was asked Q. Triplets with Given Sum Problem Given an array or list ARR consisting of N integ...read more
A Software Developer Intern was asked Q. Diamond Pattern Grid Problem Create a grid pattern of size R rows and C columns,...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Mean, Median, and Mode Problem Statement Given an integer array ARR of size N, y...read more
A Software Developer Intern was asked Q2. Triplets with Given Sum Problem Given an array or list ARR consisting of N integ...read more
A Software Developer Intern was asked Q3. Diamond Pattern Grid Problem Create a grid pattern of size R rows and C columns,...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

