Zero To DSAZero To DSA
Privacy Policy
Permutations

Subsets (Power Set)

medium
Time: O(n * 2ⁿ)
Space: O(n)

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

Constraints

  • 1 <= nums.length <= 10

Examples

Input: nums = [1,2,3]
Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
Input: nums = [0]
Output: [[],[0]]