Skip to main content

Power Set Builder

easy
RecursionBacktrackingBacktracking Subsets
Asked atAmazonMicrosoftGoogle

Problem Description

Given a list of unique integers `elements`, return all possible subsets (the power set). The returned list may be in any order, and each subset may list its elements in any order.

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

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

Constraints

  • 0 <= elements.length <= 15
  • All elements are unique
  • -100 <= elements[i] <= 100

Follow-up

Can you generate the power set iteratively using bit manipulation in O(n · 2^n) time?

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.