Return Subsets Sum to K
Given an integer array 'ARR' of size 'N' and an integer 'K', return all the subsets of 'ARR' which sum to 'K'.
Subset of an array 'ARR' is a tuple that can be obtained from 'ARR' by removing some (possibly all) elements of 'ARR'.
Note :
The order of subsets is not important.
The order of elements in a particular subset should be in increasing order of the index.
Input Format
The first line of input contains an integer 'N', which denotes the size of the array.
The second line contains 'N' single-space separated integers representing the elements of the array.
The third line contains a single integer 'K', which denotes the integer to which the subsets should sum to.
Output Format:
For each test case, print single-space separated integers of a subset of 'ARR' having sum = 'K'.
The output of each test case will be printed in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= 'N' <= 16
- (10 ^ 6) <= ARR[i] <= (10 ^ 6)
- 16 * (10 ^ 6) <= 'K' <= 16 * (10 ^ 6)
Where ‘ARR[i]’ denotes the value for ‘ith’ element of the array ‘ARR’ and 'K' is the given sum.
Time Limit: 1 sec.
CodingNinjas
author
2y
Brute Force
Recursively generate all the subsets and keep track of the sum of the elements in the current subset.
Subsets can be generated in the following way. For every element of the array, there are...read more
Help your peers!
Add answer anonymously...
Top Avalara Technologies Software Developer interview questions & answers
Popular interview questions of Software Developer
>
Avalara Technologies Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app