Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 1879 Minimum XOR Sum of Two Arrays - Problem Statement

LeetCode 1879

Given two arrays nums1 and nums2 of length nn, rearrange nums2 to find the smallest XOR sum: i=0n1(nums1[i]nums2[p[i]])\sum_{i=0}^{n-1} (\text{nums1}[i] \oplus \text{nums2}[p[i]]) where pp is a permutation. Example: nums1 =[1,2]= [1, 2], nums2 =[2,3]= [2, 3]. If we pair 11 with 33 and 22 with 22: (13)+(22)=2+0=2(1 \oplus 3) + (2 \oplus 2) = 2 + 0 = 2.

This is minimum. This is the assignment problem: match each element of nums1 to a unique element of nums2. The bitmask tracks which elements of nums2 have been used.