mediumBacktrackingPure DSA~25 min
All Distinct Subsets of a Multiset
Enumerate every distinct subset (the power set) of a collection that may contain duplicates, without repeating any subset.
Problem
Given an integer array nums that may contain duplicates, return all possible subsets (the power set) without duplicate subsets, in any order.
Input
An integer array nums, possibly with duplicates.
Output
A list of all unique subsets.
Constraints
- 1 <= nums.length <= 10
- -10 <= nums[i] <= 10
- Duplicates are possible.
Examples
Example 1
Input
nums = [1,2,2]
Output
[[],[1],[1,2],[1,2,2],[2],[2,2]]
Duplicate 2s do not produce duplicate subsets.
Example 2
Input
nums = [0]
Output
[[],[0]]
Two subsets for a single element.