mediumBacktrackingFacebookAmazon
Duplicate-Aware Powerset
A merchandise bundler generates every distinct bundle of items from a stock list that may contain duplicates.
Given an integer array nums that may contain duplicates, return all possible subsets (powerset) without duplicates.
Choose approach
1
0j
2
12
2SetUnique Subsets (1)
[]
1/6
Narrationstep 1 of 6
Emit []
Variables
cur=[]
out=1
How to think about it
- Sorted order groups duplicates.
- Within a single call, pick a duplicate value only once.
- Every node in the recursion tree emits a subset.
Edge cases to catch in interview
- All duplicates -> n+1 subsets.
- Empty input -> single empty subset.
Examples
Example 1
[[],[1],[1,2],[1,2,2],[2],[2,2]]{"values":[1,2,2]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed