Subset Sums

Return the sums of all subsets of the indexed positions in nums. Include the empty subset, whose sum is zero. Return one sum per subset in any order. Equal…

Return the sums of all subsets of the indexed positions in nums. Include the empty subset, whose sum is zero. Return one sum per subset in any order. Equal values at different indices are separate choices, and equal sums must remain repeated in the answer.

- 1 <= nums.length <= 15. - 0 <= nums[i] <= 10000. - Return exactly 2^n integer sums, where n is nums.length; do not deduplicate.

Example 1: input nums = [2,3]; output [0,2,3,5]. The empty subset, either singleton and the pair contribute sums 0, 2, 3 and 5.

Example 2: input nums = [1,1]; output [0,1,1,2]. The two indexed singleton subsets each sum to 1, so both copies of that sum remain.

Example 3: input nums = [0,2]; output [0,0,2,2]. Including or excluding zero gives distinct subsets with the same sum; retain two zeroes and two twos.

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