Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 662 |

@arpitsatnalika | 629 |

@code_it_ | 591 |

@prakharxyz | 583 |

@tujhekya | 542 |

@Rahul Jadhav 1 | 458 |

@sivanandh03 | 448 |

@satyam0460 | 433 |

@iamronak | 424 |

@imnm | 424 |

@18eumc107 | 421 |

Complete Leaderboard |

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]

]

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Subsets

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.