Problem title
Difficulty
Avg time to solve

Z Algorithm
Hard
15 mins
Implement Deque
Easy
15 mins
Single Number
Easy
10 mins
Bellman Ford
Moderate
30 mins
Print All Subsets
Easy
20 mins
Remove K Corner Elements
Easy
15 mins
Min Heap
Moderate
30 mins
MergeSort Linked List
Moderate
30 mins
Last Appearance
Moderate
38 mins
Odd even level
Easy
20 mins
16

Print All Subsets

Difficulty: EASY
Contributed By
Avg. time to solve
20 min
Success Rate
80%

Problem Statement

You are given an array ‘arr’ of ‘N’ distinct integers. Your task is to print all the non-empty subsets of the array.

Note: elements inside each subset should be sorted in increasing order. But you can print the subsets in any order, you don’t have to specifically sort them.

 

Input Format :

The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows

The first line of each test case contains a single integers ‘N’ denoting the length of the array.

The second line of each test case contains ‘N’ integers denoting the array elements.

Output Format :

For each test case print each subset in a separate line.
The subsets can be print in any order.
Output for each test case will be printed in a separate line.
Constraints :
1 <= T <= 10      
1 <= N <= 10
10^-9 <= arr[i] <= 10^9

Time limit: 1 sec
Sample Input 1 :
2
3
1 2 3
1
10
Sample Output 1 :
1
1 2
1 2 3
1 3
2
2 3
3
10
Explanation Of Sample Output 1 :
For test case 1 :
Total 7 possible subsets can be formed: {1}, {1,2}, {1,2,3}, {1,3}, {2}, {2,3}, {3}

For test case 2 :
Only a single subset {10} is possible for the given input array.
Sample Input 2 :
2
2
1 2
3
1 2 3
Sample Output 2 :
1 
1 2 
2 
1 
1 2 
1 2 3 
1 3 
2 
2 3 
3 
Reset Code
Full screen
copy-code
Console