Bitwise XOR of All Pairings

Medium Topics Company Tags

For every choice of one index from nums1 and one index from nums2, compute the bitwise XOR of those two elements. Return the XOR of all resulting values. Every index pair contributes once, including pairs whose values are duplicates. The two arrays may have different lengths.

Example 1:

Input: nums1 = [1]
nums2 = [2,3]

Output: 1

Explanation: The pairwise XORs are 1 XOR 2 = 3 and 1 XOR 3 = 2. Their XOR is 3 XOR 2 = 1.

Example 2:

Input: nums1 = [0,4]
nums2 = [1]

Output: 4

Explanation: The pairwise XORs are 0 XOR 1 = 1 and 4 XOR 1 = 5. Their XOR is 1 XOR 5 = 4.

Example 3:

Input: nums1 = [7]
nums2 = [7]

Output: 0

Explanation: There is one pair. Its XOR is 7 XOR 7 = 0.

Constraints:

  • 1 <= nums1.length, nums2.length <= 100000
  • 0 <= nums1[i], nums2[j] <= 1000000000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.