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.
Be the first one to answer
Add answer anonymously...
OpenText Technologies Full Stack Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter