
Asked in OpenText Technologies
Find All Subsets
Given an array arr
consisting of 'N' distinct integers, your task is to generate all possible non-empty subsets of the given array.
You can return the subsets in any order.
Input:
The first line contains a single integer ‘T’ representing the number of test cases.
Each test case consists of:
The first line contains a single integer ‘N’, representing the number of elements in the array.
The second line contains ‘N’ space-separated integers, the elements of the array.
Output:
For each test case, print each subset on a new line.
Each test case's output should be separated by a blank line.
Example:
Input:
2
3
1 2 3
2
4 5
Output:
1
2
1 2
3
1 3
2 3
1 2 3
4
5
4 5
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 10
10-9 ≤ arr[i] ≤ 109
- Time limit: 1 sec
Note:
It is assumed that printing functionality is already managed. Implement the function to generate the subsets.

AnswerBot
4mo
Generate all possible non-empty subsets of a given array of distinct integers.
Use recursion to generate all subsets by including or excluding each element in the array.
Maintain a current subset and it...read more
Help your peers!
Add answer anonymously...
Interview Questions Asked to Full Stack Engineer at Other Companies
Top Skill-Based Questions for OpenText Technologies Full Stack Engineer
Algorithms Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 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

