Power Set (All Subsets)

Easy
recursion Google Meta Amazon

Generate all subsets (the power set) of a given list of unique integers. Return them sorted by length, then lexicographically.

Example

power_set([1, 2, 3])
# => [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]

Test Cases

Python Editor

Output

Click "Run" to see results...