#1879
Minimum XOR Sum of Two Arrays
candidate master · 1405 · lc hard +32 · verified · 50.6% accepted · 718 likes · top 39%
Description
You are given two integer arrays nums1 and nums2 of the same length n. The XOR sum is defined as sum of (nums1[i] XOR nums2[i]) for all i.
Rearrange nums2 in any order to minimize this XOR sum, then return the minimized value.
Example 1:
Input: nums1 = [1,2], nums2 = [2,3]
Output: 2
Explanation: Rearrange nums2 so that it becomes [3,2].
The XOR sum is (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2.
Example 2:
Input: nums1 = [1,0,3], nums2 = [5,3,4]
Output: 8
Explanation: Rearrange nums2 so that it becomes [5,4,3].
The XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8.
Code
1
2
3