values. The XOR of a collection of numbers is the bitwise exclusive OR of all of them; for an empty collection it is 0.
Go through every subset of the array, including the empty one and the whole array, compute its XOR, and return the sum of all these results. Subsets are told apart by which positions they pick, so subsets with equal values taken from different places are counted separately.values=[2, 3] → 6
The subsets are the empty one (0), [2] (2), [3] (3) and [2,3] (2 XOR 3 = 1). The sum is 0 + 2 + 3 + 1 = 6.
values=[4, 4] → 8
The empty subset gives 0, each of the two singles gives 4, and the pair gives 4 XOR 4 = 0. Total 8: equal elements still count as different picks.
values=[1, 2, 4] → 28
The eight subsets give XORs 0 through 7, which sum to 28.
values.length ≤ 12values[i] ≤ 10⁶values=[2, 3]
6
Run checks the first 3 tests in your browser. Submit checks all 99 tests on the server, hidden ones included.