Sum of Subset XOR Totals

Implement subsetXorSum

Define a subset's XOR total by folding its elements together with XOR — the empty subset has nothing to fold, so its total is just 0. Sum that total over every subset nums has, counting each subset once even if two subsets happen to share the same elements or the same total, and return the overall sum. Enumerating every subset works directly, and with at most 12 elements there are never more than 4096 of them to walk. But there's a shortcut hiding in the structure: any bit that shows up in at least one element ends up set in exactly half of all the subset totals, so its contribution to the final sum is fixed regardless of exactly which elements carry it. That collapses the whole computation to a single OR across every element, scaled by how many subsets share each bit.

Example 1:

Input: nums = [1,3]

Output: 6

Example 2:

Input: nums = [5,1,6]

Output: 28

Example 3:

Input: nums = [3,4,5,6,7,8]

Output: 480

+ 10 hidden test cases run on Submit.

Constraints:

  • 1 ≤ nums.length ≤ 12
  • 1 ≤ nums[i] ≤ 20

nums =

[1, 3]