mediumBacktrackingFacebookAmazonBloomberg
Powerset Expander
A feature-flag planner enumerates every possible on/off combination of distinct toggles.
Given an array of distinct integers, return all possible subsets. The solution set must not contain duplicate subsets.
Choose approach
1
0i
2
13
2SetSubsets so far (0)
empty
1/24
Narrationstep 1 of 24
Start DFS at index 0.
Variables
depth=0
cur=[]
outCount=0
How to think about it
- Each element contributes an independent binary choice.
- Backtrack by popping after the include branch returns.
- Depth = n -> leaf emits one subset.
Edge cases to catch in interview
- Empty input -> single empty subset.
- Duplicates are forbidden by the problem.
Examples
Example 1
[[],[3],[2],[2,3],[1],[1,3],[1,2],[1,2,3]]{"values":[1,2,3]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed