This practice workspace is built for desktop. Open it on a larger screen to start solving.
Subsets
Given an integer array nums of unique elements, return all possible subsets (the power set).
The solution set must not contain duplicate subsets. For deterministic comparison, sort each inner subset in ascending order and sort the outer list lexicographically by its element sequence (compare element-by-element; a shorter prefix sorts before a longer one with the same prefix).
The empty array's power set is [[]]. For n elements there are exactly 2^n subsets.
Examples
Constraints
- 1 <= nums.length <= 10
- -10 <= nums[i] <= 10
- All elements of nums are unique.
Preview Mode
This is a read-only preview of DSAMind's AI coaching. Sign up to get custom feedback on your own solution.
Your approach
- Pattern:Backtracking
- Time:O(N)
- Space:O(1)
Complete approach — pattern and complexity both named.
Coach
What you got right
You correctly matched the sorted input requirement and implemented a linear-time scan using two pointers.
Where it diverged
No divergence detected. The code correctly aligns with the stated approach.
Next attempt: focus on
Try solving related sliding window problems to build familiarity with two-pointer variants.
Signals
No signals fired — clean run, you stayed in flow.