Skip to content

Practice Minimum XOR Sum of Two Arrays

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1879
LeetCode Problem

Minimum XOR Sum of Two Arrays

Problem Statement

You are given two integer arrays nums1 and nums2 of length n. The XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed). Rearrange the elements of nums2 such that the resulting XOR sum is minimized. Return the XOR sum after the rearrangement.

Source: Minimum XOR Sum of Two Arrays on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums1 = [1,2], nums2 = [2,3]
Output
2

# Example 2

Input
nums1 = [1,0,3], nums2 = [5,3,4]
Output
8

Constraints

n == nums1.length
n == nums2.length
1 <= n <= 14
0 <= nums1[i], nums2[i] <= 10^7

Related LeetCode Problems

Practice more problems similar to Minimum XOR Sum of Two Arrays.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.