Generate Superset - aloalgo

Generate Superset

Medium

You are given an integer array nums of unique elements.

Your task is to generate the superset of nums — that is, return all possible subsets (the power set) of nums.

You may assume that:

  • All elements of nums are unique.

Return a list of all possible subsets. The order of the result and the order of elements within each subset do not matter.

Example 1

Input
[0]
Output
[
  [],
  [0]
]
Explanation:

The superset of a single-element set contains the empty set and the set itself.

Example 2

Input
[0, 1]
Output
[
  [],
  [0],
  [1],
  [0, 1]
]
Explanation:

For two elements there are four possible subsets: the empty set, each singleton, and the full set.

Example 3

Input
[0, 1, 2]
Output
[
  [],
  [0],
  [1],
  [2],
  [0, 1],
  [0, 2],
  [1, 2],
  [0, 1, 2]
]
Explanation:

For three elements there are 2^3 = 8 possible subsets.

Loading...
Input
[0]
Output
[
  [],
  [0]
]

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!