Subsets

Given nums containing distinct integers, return all possible subsets, including the empty subset. Return every subset exactly once. The order of the result…

Given nums containing distinct integers, return all possible subsets, including the empty subset. Return every subset exactly once. The order of the result rows and the order of values inside each row do not matter. Each input value may be selected at most once.

- 1 <= nums.length <= 10. - -10 <= nums[i] <= 10. - All values in nums are distinct.

Example 1: input nums = [1,2,3]; output [[],[1],[1,2],[1,2,3],[1,3],[2],[2,3],[3]]. Three independent include-or-exclude decisions give eight subsets, from choosing nothing to choosing all three values.

Example 2: input nums = [0]; output [[],[0]]. The empty subset chooses no value; [0] chooses the zero. They are distinct subsets.

Example 3: input nums = [2,-1]; output [[],[-1],[-1,2],[2]]. A negative value still has both choices. Choose neither, either value alone, or both values; no sum-based pruning applies.

Category: Recursion. Topic: recursion. Difficulty: Medium. Patterns: backtracking.