Subsets
Given an integer array nums of unique elements, return all possible subsets (the power set).
Output each subset on a separate line as space-separated integers (empty subset as empty line). Subsets sorted by size, then lexicographically.
Example
1,2,3
1 2 3 1 2 1 3 2 3 1 2 3
- The problem starts by generating subsets of size 1 from the input array
nums = [1,2,3], resulting in subsets[1],[2], and[3]. - Next, it generates subsets of size 2 by combining each pair of unique elements:
[1,2],[1,3], and[2,3]. - Then, it generates the subset of size 3, which includes all elements:
[1,2,3]. - The subsets are then sorted first by size (from smallest to largest) and then lexicographically, resulting in the output:
1 2 3 1 2 1 3 2 3 1 2 3
Constraints
- 1 <= len(nums) <= 10
- -10 <= nums[i] <= 10
- All elements are unique