Ctrl K

XOR of Every Cross Pair

Medium
You are given two arrays of non-negative integers, left and right. Form every pair that takes one number from left and one from right, so each element of left is paired with each element of right exactly once. For each pair, compute the bitwise XOR of its two numbers. Return the bitwise XOR of all those values. There can be up to 10¹⁰ pairs, so listing them all is out of the question; look for a pattern.
Example 1
left=[6, 9], right=[4, 1, 7] → 15

The pairs give 6^4=2, 6^1=7, 6^7=1, 9^4=13, 9^1=8, 9^7=14. The XOR of all six is 2^7^1^13^8^14 = 15.

Example 2
left=[5, 5], right=[3, 12] → 0

Every number takes part in an even number of pairs, so everything cancels out and the result is 0.

Example 3
left=[11], right=[2] → 9
Constraints
  • 1 ≤ len(left), len(right) ≤ 10⁵
  • 0 ≤ left[i], right[j] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTake From Any Pile MediumLongest Stretch with the Top AND MediumOR of All Subset Sums MediumSmallest Unreachable OR MediumXOR Tile Duel Hard
loading Python…
Input
left=[6, 9], right=[4, 1, 7]
Expected
15

Run checks the first 3 tests in your browser. Submit checks all 99 tests on the server, hidden ones included.