Enumerate Distinct Subsets with Repeated Input Values
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
Return all distinct subsets of the integer entries in `nums`, which may contain repeated values. Each subset may use a value no more times than it occurs in the input. Include the empty subset, but do not return the same value-multiset more than once. The collection may appear in any order.
```cpp
vector<vector<int>> subsetsWithDup(vector<int>& nums);
```
Member presentation order does not create a different subset.
### Examples
```text
Input: nums = [-1,-1,2]
One valid output: [[],[-1],[-1,-1],[2],[-1,2],[-1,-1,2]]
```
```text
Input: nums = [3,3]
One valid output: [[3,3],[],[3]]
```
### Constraints & Assumptions
- `1 <= nums.length <= 10`.
- Every entry lies between -10 and 10, inclusive.
- Repeated input values are allowed and their available multiplicities matter.
### Clarifying Questions to Ask
- May a subset contain two equal values? Yes, if the input contains at least two copies.
- Do choosing different occurrences of the same values create different subsets? No.
```hint Keep multiplicity separate from duplication
Two copies of one value may belong in a valid subset, while two returned subsets with the same member multiplicities are duplicates.
```
### What a Strong Answer Covers
- Complete enumeration with the correct multiplicities and no repeated subsets.
- Inclusion of both empty and full value-multisets.
- A duplicate-avoidance argument and output-sensitive complexity.
### Follow-up Questions
- How does an all-equal input change the number of distinct subsets?
- How should a judge compare collections whose subset or member orders differ?
Overview: Enumerate distinct subsets of a duplicate-containing array while preserving available value multiplicities and free output order.
Enumerate Distinct Subsets with Repeated Input Values
Meta
Oct 12, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0
Problem
Return all distinct subsets of the integer entries in nums, which may contain repeated values. Each subset may use a value no more times than it occurs in the input. Include the empty subset, but do not return the same value-multiset more than once. The collection may appear in any order.