Skip to main content

Unique Subset Generator

easy
BacktrackingArrayCombinatoricsBacktracking Subsets
Asked atAmazonGoogleMicrosoftBloomberg

Problem Description

Given an integer array `collection` of **distinct** integers, return **all possible subsets** (the power set).

The solution set must not contain duplicate subsets. Return the answer in any order.

**Example 1:**
```
Input: collection = [3, 1, 2]
Output: [[], [3], [1], [2], [3,1], [3,2], [1,2], [3,1,2]]
```

**Example 2:**
```
Input: collection = [8]
Output: [[], [8]]
```

Constraints

  • 1 <= collection.length <= 10
  • All elements in collection are distinct
  • -15 <= collection[i] <= 15

Follow-up

How would you handle duplicates in `collection` so that the output still contains no duplicate subsets?

Hints

Try the problem first. If you get stuck, you can reveal hints one at a time.

Solution

Leaderboard

No entries yet for python.

Be the first — submit an accepted solution.