Given two integer arrays nums1 and nums2 of equal length n, you may reorder the elements of nums2 arbitrarily. After applying your chosen permutation to nums2, the XOR sum is defined as
where denotes the bitwise XOR operation. Your task is to find and return the smallest possible XOR sum achievable by optimally rearranging nums2.
Example 1:
Input: nums1 = [4, 7], nums2 = [2, 8]
Output: 17
Explanation: Reorder nums2 to [8, 2]; the XOR sum becomes (4 ^ 8) + (7 ^ 2) = 12 + 5 = 17.
nums1 = [4,7] nums2 = [2, 8]
17
We are given two arrays nums1 = [4, 7] and nums2 = [2, 8].
Example 2:
Input: nums1 = [5, 2, 9], nums2 = [8, 4, 1]
Output: 5
Explanation: One optimal permutation is [4, 1, 8], giving (5 ^ 4) + (2 ^ 1) + (9 ^ 8) = 1 + 3 + 1 = 5.
Example 3:
Input: nums1 = [10], nums2 = [20]
Output: 30
Constraints:
1 <= n <= 140 <= nums1[i], nums2[i] <= 5,000,000The function signature provided to the judge is min_xor_sum(nums1, nums2), and you must return the minimum XOR sum.
Input:
2
1 2
2 3
Output:
2
nums1 = [4,7] nums2 = [2, 8]
17
We are given two arrays nums1 = [4, 7] and nums2 = [2, 8].