We’re preparing your current view and syncing the latest data.
Given an integer array nums, find the sum of XOR totals of every subset of nums. The XOR total of a subset is defined as the XOR of all elements in that subset. Note that the XOR total of an empty subset is 0.
Return the sum of all XOR totals for every subset of nums.
An integer array nums of length n, where 1 <= n <= 12 and 0 <= nums[i] <= 10^5.
Return an integer, the sum of XOR totals for every subset of nums.
1 <= nums.length <= 12 0 <= nums[i] <= 10^5
Example 1
Input
[1,3]
Output
6
Explanation
All subsets are: [] (XOR 0), [1] (XOR 1), [3] (XOR 3), [1,3] (XOR 2). Sum is 0+1+3+2=6.
Example 2
Input
[5,1,6]
Output
28
Explanation
All subsets and their XOR totals: []=0, [5]=5, [1]=1, [6]=6, [5,1]=4, [5,6]=3, [1,6]=7, [5,1,6]=2. Sum=0+5+1+6+4+3+7+2=28.