Return Subsets Sum to K Problem Statement
Given an integer array 'ARR' of size 'N' and an integer 'K', return all the subsets of 'ARR' which sum to 'K'.
Explanation:
A 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:
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:
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.
Example:
Input:
3
1 2 3
3
Output:
1 2
3
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.

AnswerBot
4mo
Given an array and an integer, return all subsets that sum to the given integer.
Use backtracking to generate all possible subsets of the array.
For each subset, check if the sum equals the given intege...read more
Help your peers!
Add answer anonymously...
Top SDE Interview Questions Asked at Infosys
Q. What is annotation in Spring Boot?
Q. Count Inversions Problem Statement Given an integer array ARR of size N containi...read more
Q. Boundary Traversal of Binary Tree Given a binary tree of integers, your task is ...read more
Interview Questions Asked to SDE at Other Companies
Top Skill-Based Questions for Infosys SDE
Data Structures Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
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

