Loading...
Given an array nums, the XOR total of a subset is the bitwise XOR of its elements, and 0 for the empty subset. For example, the XOR total of [2,5,6] is 2 XOR 5 XOR 6 = 1.
Return the sum of the XOR totals of every subset of nums, including the empty subset and nums itself.
Subsets are identified by which positions of nums they take, not by their values, so two subsets holding equal values are still counted separately. An array of length n therefore always has exactly 2n subsets.
Input: nums = [1,3]
Output: 6
Explanation: The 4 subsets have XOR totals 0 (empty), 1, 3, and 1 XOR 3 = 2. Their sum is 0 + 1 + 3 + 2 = 6.
Input: nums = [5,1,6]
Output: 28
Explanation: The 8 subsets have XOR totals 0, 5, 1, 6, 5 XOR 1 = 4, 5 XOR 6 = 3, 1 XOR 6 = 7, and 5 XOR 1 XOR 6 = 2. Their sum is 0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28.
Input: nums = [3,4,5,6,7,8]
Output: 480
Explanation: There are 64 subsets; their XOR totals sum to 480.
nums.length ≤12nums[i] ≤20Click "Run" to test with sample cases or "Submit" to run all tests.