Problem · Array
Sum of XOR Across Cartesian Pairs
Learn this problemProblem statement
Given two arrays of nonnegative integers, left and right, consider every ordered pair (left[i], right[j]).
Return the sum of left[i] XOR right[j] over all such pairs.
Function
sumPairXor(left: int[], right: int[]) → longExamples
Example 1
left = [1,2]right = [3,4]return = 14The four XOR values are 1 XOR 3 = 2, 1 XOR 4 = 5, 2 XOR 3 = 1, and 2 XOR 4 = 6. Their sum is 14.
Example 2
left = [0,7]right = [7]return = 7The pair values are 0 XOR 7 = 7 and 7 XOR 7 = 0.
Constraints
1 <= left.length, right.length <= 200000 <= left[i], right[j] <= 10^9- The answer fits in a signed 64-bit integer.