Generate All Subsets
MediumP1Coding
Given an integer n, return all subsets of the integers 1 to n, including the empty subset and the full set. Return the subsets in any order. Inside each subset the numbers must be in increasing order.
For n = 0 the only subset is the empty one.
Example 1
- Input
- n = 3
- Output
- [[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]
Example 2
- Input
- n = 1
- Output
- [[],[1]]
Example 3
- Input
- n = 0
- Output
- [[]]
Constraints
- 0 <= n <= 10
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 7. ⌘Enter runs, ⌘⇧Enter submits.