Subsets
Submissions: 6002   Accuracy:

28.79%

  Difficulty: Medium   Marks: 4
Associated Course(s):   Sudo Placement 2019

Given an array of integers that might contain duplicates, return all possible subsets.

Note:

        Elements in a subset must be in non-descending order.
        The solution set must not contain duplicate subsets.
        The subsets must be sorted lexicographically.

Input:
First line of input contains number of testcases T. For each testcase, there will be two line of input, first of which contains N and next contains N space seperated integers. Every test case has two lines. First line is N, size of array.

Output:
One line per test case, every subset enclosed in () and in every set intergers should be space seperated.(See example)

Constraints:
1 <= T <= 500
1 <= N <= 12

1 <= x <= 9

Example:
Input:
2
3
1 2 2
4
1 2 3 3

Output:
()(1)(1 2)(1 2 2)(2)(2 2)
()(1)(1 2)(1 2 3)(1 2 3 3)(1 3)(1 3 3)(2)(2 3)(2 3 3)(3)(3 3)

Explanation:
Testcase 1:
Subsets are
[
[],
[1],
[1,2],
[1,2,2],
[2],
[2, 2]
]

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: dhruvi


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.