119. Subsets II — Duplicates
List the different multisets you can choose from the input occurrences. Each occurrence can be used at most once, so a repeated value may be chosen as many times as it appears.
Different position selections that yield the same value subset must not create duplicate output rows. Preserve the contract's ordering and ownership rules.
Example 1
Input
[2,1,2]
Output
[[],[1],[1,2],[1,2,2],[2],[2,2]]
Explanation: Sorting a clone makes equal choices adjacent; two copies of 2 may be chosen on successive depths.
Example 2
Input
[]
Output
[[]]
Explanation: The root path is a valid subset and must be emitted.
Example 3
Input
[7,7,7]
Output
[[],[7],[7,7],[7,7,7]]
Explanation: Four multiplicity choices exist, rather than eight distinct value subsets.
Constraints
0 <= nums.length <= 16-231 <= nums[i] <= 231 - 1
Hints
Hint 1
Keep the increasing-index frontier from ordinary subsets.
Hint 2
Sort a clone so equal sibling choices become adjacent.
Hint 3
Emit a snapshot at entry, skip i>start duplicates, recurse from i+1, then undo.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
Equal siblings collapse while deeper copies remain
[2,1,2]
[[],[1],[1,2],[1,2,2],[2],[2,2]]