Given an integer array nums of unique elements, return all possible subsets (the power set), excluding the full set itself.
The solution set must not contain duplicate subsets. Return the solution with each subset's elements in ascending order, and the outer list sorted lexicographically.
Function Signature
def subsets_without_full(nums: list[int]) -> list[list[int]]:
Rules
-
The empty subset is included. Only the subset that contains every element of
nums
is left out.
-
Lexicographic order compares two subsets element by element from the left, the way Python compares lists. A subset that is a prefix of a longer one comes first, so
[1]
comes before
[1, 2]
.
-
The order of
nums
in the input does not change the output.
Constraints
-
1 <= len(nums) <= 10
-
-10 <= nums[i] <= 10
-
All the numbers of
nums
are unique.
Examples
Input: nums = [1, 2, 3]
Output: [[], [1], [1, 2], [1, 3], [2], [2, 3], [3]]
These are all subsets of [1, 2, 3] except [1, 2, 3] itself: seven of the eight, in lexicographic order.
Input: nums = [0]
Output: [[]]
The only subsets of [0] are [] and [0]. Excluding the full set [0] leaves just [].
Input: nums = [2, -5]
Output: [[], [-5], [2]]
The full set is [-5, 2] once its elements are sorted, and it is dropped. Of the rest, [] comes first because it is a prefix of every list, then [-5] comes before [2] because -5 < 2.