Class Solution
java.lang.Object
g1801_1900.s1879_minimum_xor_sum_of_two_arrays.Solution
1879 - Minimum XOR Sum of Two Arrays.<p>Hard</p>
<p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> of length <code>n</code>.</p>
<p>The <strong>XOR sum</strong> of the two integer arrays is <code>(nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1])</code> ( <strong>0-indexed</strong> ).</p>
<ul>
<li>For example, the <strong>XOR sum</strong> of <code>[1,2,3]</code> and <code>[3,2,1]</code> is equal to <code>(1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4</code>.</li>
</ul>
<p>Rearrange the elements of <code>nums2</code> such that the resulting <strong>XOR sum</strong> is <strong>minimized</strong>.</p>
<p>Return <em>the <strong>XOR sum</strong> after the rearrangement</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums1 = [1,2], nums2 = [2,3]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> Rearrange <code>nums2</code> so that it becomes <code>[3,2]</code>. The XOR sum is (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums1 = [1,0,3], nums2 = [5,3,4]</p>
<p><strong>Output:</strong> 8</p>
<p><strong>Explanation:</strong> Rearrange <code>nums2</code> so that it becomes <code>[5,4,3]</code>. The XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums1.length</code></li>
<li><code>n == nums2.length</code></li>
<li><code>1 <= n <= 14</code></li>
<li><code>0 <= nums1[i], nums2[i] <= 10<sup>7</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumXORSum
public int minimumXORSum(int[] nums1, int[] nums2)
-