#1835
Find XOR Sum of All Pairs Bitwise AND
expert · 1135 · lc hard +32 · verified · 62.5% accepted · 627 likes · top 64%
Description
The XOR sum of a list is the bitwise XOR of all its elements (or 0 for an empty list).
Given two 0-indexed arrays arr1 and arr2 of non-negative integers, compute the XOR sum of all values arr1[i] AND arr2[j] for every index pair (i, j).
Return the result.
Example 1:
Input: arr1 = [1,2,3], arr2 = [6,5]
Output: 0
Explanation: The list = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1].
The XOR sum = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0.
Example 2:
Input: arr1 = [12], arr2 = [4]
Output: 4
Explanation: The list = [12 AND 4] = [4]. The XOR sum = 4.
Code
1
2
3