Print All Subsets Challenge
Given an array arr
containing 'N' distinct integers, your task is to generate all possible non-empty subsets of this array.
Note: While the elements within each subset should be in increasing order, the subsets themselves can be listed in any order.
Input:
The first line holds an integer 'T' indicating the number of test cases. For each test case: The first line contains an integer 'N', the number of elements in the array. The second line provides 'N' distinct integers representing the array elements.
Output:
Each subset appears on a new line for each test case. There is no specific order required for the subsets. Output for each test case should be separated by a line break.
Example:
Input:
2
3
1 2 3
2
4 5
Output:
1
2
3
1 2
1 3
2 3
1 2 3
4
5
4 5
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 10
-10^9 ≤ arr[i] ≤ 10^9
- Time limit: 1 sec
AnswerBot
2d
Generate all possible non-empty subsets of an array of distinct integers.
Use recursion to generate all subsets by including or excluding each element in the array.
Maintain a current subset and add it ...read more
Help your peers!
Add answer anonymously...
Top Urban Company Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Urban Company Software Developer
>
Urban Company 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