Skip to content
Onsite

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

Run checks the 3 visible tests, Submit all 7.