Subsets
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. **Examples:** ```typescript subsets([1, 2, 3]) // [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] subsets([0]) // [[],[0]] ```
Solve It in the BrowserPractice Explaining It Out Loud
Optimal Approach
- Time complexity: O(n * 2^n)
- Space complexity: O(n)
There are 2^n total subsets, and each subset takes O(n) time to copy into the result.
Follow-Up Questions Interviewers Ask About Subsets
- Can you generate subsets using bit manipulation?
Yes, iterate from 0 to (2^n - 1) and include nums[i] if the i-th bit is set to 1.
Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.