Loading...
Loading...
Loading...
A list of n numbers may contain repeats. Sort it, then print every different subset once. Smaller subsets come first, and subsets of the same size come in dictionary order. Separate numbers with a space and print the empty subset as -.
Example
Input
3 1 2 2
Output
- 1 2 1 2 2 2 1 2 2
Six different subsets.
Try the problem first. Open one hint at a time.
Sort first so equal numbers are neighbours.
Inside the loop, skip a number equal to the previous one when i is greater than the start index.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor