#2425

Bitwise XOR of All Pairings

specialist · 610 · lc medium +29 · verified · 66.9% accepted · 920 likes · top 73%

Description

You are given two 0-indexed integer arrays nums1 and nums2 of lengths m and n respectively.

Consider an array formed by concatenating one copy of nums1 and one copy of nums2. Compute the bitwise XOR of every pair (nums1[i], nums2[j]) for all valid indices i and j, and XOR all those results together.

Return the final value.

Example 1:

Input: nums1 = [2,1,3], nums2 = [10,2,5,0]
Output: 13
Explanation:
A possible nums3 array is [8,0,7,2,11,3,4,1,9,1,6,3].
The bitwise XOR of all these numbers is 13, so we return 13.

Example 2:

Input: nums1 = [1,2], nums2 = [3,4]
Output: 0
Explanation:
All possible pairs of bitwise XORs are nums1[0] ^ nums2[0], nums1[0] ^ nums2[1], nums1[1] ^ nums2[0],
and nums1[1] ^ nums2[1].
Thus, one possible nums3 array is [2,5,1,6].
2 ^ 5 ^ 1 ^ 6 = 0, so we return 0.

Code

1
2
3