1375. Minimum XOR Sum of Two Arrays

HardBit ManipulationBitmask DPXORAssignment

Given two arrays of equal length n, rearrange the second array however you like and then sum nums1[i] XOR nums2[i] over all positions. Return the smallest sum achievable over all rearrangements.

Input: A JSON object {"nums1": [<integers>], "nums2": [<integers>]} of equal length.

Output: Return the minimum possible XOR sum.

Examples

Example 1
Input: {"nums1":[1,2],"nums2":[2,3]}
Output: 2
Explanation: Pairing 1 with 3 and 2 with 2 gives 2 + 0 = 2.
Example 2
Input: {"nums1":[1,0,3],"nums2":[5,3,4]}
Output: 8
Explanation: The optimal rearrangement gives an XOR sum of 8.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →