Imagine you have two arrays of non-negative integers, nums1 and nums2. Your task is to create all possible pairs where you take one number from nums1 and one number from nums2, then calculate the bitwise XOR of each pair.
For example, if nums1 = [2, 1] and nums2 = [1, 3], you would create pairs: (2, 1), (2, 3), (1, 1), and (1, 3). The XOR values would be [3, 1, 0, 2].
Finally, you need to return the XOR of all these XOR values. This might seem like you need to compute all pairs explicitly, but there's a clever mathematical pattern that can solve this much more efficiently!
Can you find the pattern that avoids computing all O(m×n) pairs?
Input & Output
Visualization
Time & Space Complexity
We need to generate all m × n pairs and compute XOR for each
Only using a constant amount of extra space for the result variable
Constraints
- 1 ≤ nums1.length, nums2.length ≤ 105
- 0 ≤ nums1[i], nums2[j] ≤ 109
- Arrays contain only non-negative integers