Subset Sum Equal To K Problem Statement

Given an array/list of positive integers and an integer K, determine if there exists a subset whose sum equals K.

Provide true if such a subset exists, otherwise return false.

Example:

Input:
ARR = {1,2,3,4}, K = 4
Output:
true
Explanation:

There exist subsets like {1,3} and {4} where the sum is 4, so the output is true.

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 10^3
  • 0 ≤ ARR[i] ≤ 10^9
  • 0 ≤ K ≤ 10^9
  • Time Limit: 1 sec
Anonymous
14d
def CheckForSequence(arr, n, k) : # Traverse the array from end # to start for i in range(n - 1, -1, -1) : # if k is greater than # arr[i] then subtract # it from k if (k >= arr[i]) : k = k - arr[i]; ...read more
Help your peers!
Add answer anonymously...
JPMorgan Chase & Co. Machine Learning Engineer 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