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
1mo

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
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