Loading
Loading
A product team ships optional features, each identified by a distinct integer id. Before launch they want to review every bundle a customer could switch on — including switching nothing on.
Return every subset of ids. Write each bundle as its ids in increasing order, comma-separated inside square brackets with no spaces (the empty bundle is []). List the bundles in lexicographic order as number sequences: compare the first ids, then the second, and so on, with a bundle that is a prefix of another coming first.
ids = [3, 1, 2][]the empty bundle is recorded first[1] → [1,2] → [1,2,3]keep extending with larger ids[1,3]back out of 2, try 3 after 1[2] → [2,3], then [3]start over from the next id["[]", "[1]", "[1,2]", "[1,2,3]", "[1,3]", "[2]", "[2,3]", "[3]"]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Eight bundles. Each lists its ids in increasing order, and the bundles are ordered as number sequences, so [1,2,3] comes before [1,3].
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(2ⁿ · n) time · O(n) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Example 2
The empty bundle and the bundle holding only 5.