Subsets - Problem
Given an integer array nums of unique elements, return all possible subsets (the power set).
The solution set must not contain duplicate subsets. Return the solution in any order.
Note: The power set of a set is the set of all its subsets, including the empty set and the set itself.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2,3]
›
Output:
[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
💡 Note:
All possible combinations of including/excluding each element. Empty set and full set are both included.
Example 2 — Two Elements
$
Input:
nums = [0]
›
Output:
[[],[0]]
💡 Note:
With one element, we have 2¹ = 2 subsets: empty set and the single element.
Example 3 — Larger Array
$
Input:
nums = [1,2]
›
Output:
[[],[1],[2],[1,2]]
💡 Note:
With two elements, we have 2² = 4 subsets representing all include/exclude combinations.
Constraints
- 1 ≤ nums.length ≤ 10
- -10 ≤ nums[i] ≤ 10
- All the numbers of nums are unique
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array of unique integers [1,2,3]
2
Process
Generate all combinations of include/exclude
3
Output
2^n subsets including empty set
Key Takeaway
🎯 Key Insight: Each element has 2 choices (include/exclude), leading to 2^n total combinations
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code