1879. Minimum XOR Sum of Two Arrays Hard
1/**
2 * [1879] Minimum XOR Sum of Two Arrays
3 *
4 * You are given two integer arrays nums1 and nums2 of length n.
5 * 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).
6 *
7 * For example, the XOR sum of [1,2,3] and [3,2,1] is equal to (1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4.
8 *
9 * Rearrange the elements of nums2 such that the resulting XOR sum is minimized.
10 * Return the XOR sum after the rearrangement.
11 *
12 * Example 1:
13 *
14 * Input: nums1 = [1,2], nums2 = [2,3]
15 * Output: 2
16 * Explanation: Rearrange nums2 so that it becomes [3,2].
17 * The XOR sum is (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2.
18 * Example 2:
19 *
20 * Input: nums1 = [1,0,3], nums2 = [5,3,4]
21 * Output: 8
22 * Explanation: Rearrange nums2 so that it becomes [5,4,3].
23 * The XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8.
24 *
25 *
26 * Constraints:
27 *
28 * n == nums1.length
29 * n == nums2.length
30 * 1 <= n <= 14
31 * 0 <= nums1[i], nums2[i] <= 10^7
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/minimum-xor-sum-of-two-arrays/
37// discuss: https://leetcode.com/problems/minimum-xor-sum-of-two-arrays/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn minimum_xor_sum(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_1879() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.