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
4mo
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...
Urban Company Software Developer interview questions & answers
A Software Developer was asked 9mo agoQ. What is a thread?
A Software Developer was asked 10mo agoQ. You are given an array of prices where prices[i] is the price of a given stock o...read more
A Software Developer was asked 10mo agoQ. Given a sorted array of integers nums and an integer target, write a function th...read more
Popular interview questions of Software Developer
A Software Developer was asked 9mo agoQ1. What is a thread?
A Software Developer was asked 10mo agoQ2. You are given an array of prices where prices[i] is the price of a given stock o...read more
A Software Developer was asked 10mo agoQ3. Given a sorted array of integers nums and an integer target, write a function th...read more
>
Urban Company Software Developer Interview 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

