Loading...
Loading...
Loading...
A shopper has n different item codes. Print every subset of the list, smaller subsets first. Subsets of the same size are printed in the order you get by choosing items from left to right. Items inside a subset keep their input order. The empty subset is printed as -.
Example
Input
3 5 7 9
Output
- 5 7 9 5 7 5 9 7 9 5 7 9
Eight subsets.
Try the problem first. Open one hint at a time.
Use a start index: each call may only choose items to the right of the last chosen item.
Save a copy of the path at the start of every call, then sort the saved subsets by their size. Python's sort keeps equal sizes in their saved order.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor