826. Minimum XOR Sum of Two Arrays (Bitmask Recursion)

HardRecursionRecursion

Given two integer arrays a and b of equal length n, rearrange b to minimize the sum of a[i] XOR b[perm[i]] for all i. Return the minimum XOR sum. Input: JSON {a, b}.

Input: JSON {a, b}.

Output: Integer.

Examples

Example 1
Input: {"a":[1,2],"b":[2,3]}
Output: 2
Explanation: 1^3 + 2^2 = 2+0 = 2.
Example 2
Input: {"a":[1,0,3],"b":[5,3,4]}
Output: 8
Explanation: Optimal assignment yields XOR sum 8.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →