K Sum Subset Problem Statement

Given an array arr of size 'N' and an integer 'K', determine the maximum subset sum of the array that does not exceed 'K'.

Example:

Input:
arr = [1, 3, 5, 9], K = 16
Output:
15
Explanation:

By selecting the subset [9, 5, 1], the sum is 15 which is the maximum possible below or equal to 16.

Input:

T (number of test cases)
N K
arr[1] arr[2] ... arr[N]

Output:

Maximum subset sum ≤ K for each test case

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 40
  • 0 <= K <= 10^9
  • 0 <= arr[i] <= 10^9
  • Time Limit: 1 sec
Note:

No need to print the output; focus on implementing the function to return the result.

AnswerBot
1mo

Find the maximum subset sum of an array that does not exceed a given integer K.

  • Use dynamic programming to solve this problem efficiently.

  • Iterate through all possible subsets of the array and keep trac...read more

Help your peers!
Add answer anonymously...
Nagarro Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter