|
| 1 | +/** |
| 2 | + * [1787] Make the XOR of All Segments Equal to Zero |
| 3 | + * |
| 4 | + * You are given an array nums and an integer k. The <font face="monospace">XOR</font> of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] XOR ... XOR nums[right]. |
| 5 | + * Return the minimum number of elements to change in the array such that the XOR of all segments of size k is equal to zero. |
| 6 | + * |
| 7 | + * Example 1: |
| 8 | + * |
| 9 | + * Input: nums = [1,2,0,3,0], k = 1 |
| 10 | + * Output: 3 |
| 11 | + * Explanation: Modify the array from [<u>1</u>,<u>2</u>,0,<u>3</u>,0] to from [<u>0</u>,<u>0</u>,0,<u>0</u>,0]. |
| 12 | + * |
| 13 | + * Example 2: |
| 14 | + * |
| 15 | + * Input: nums = [3,4,5,2,1,7,3,4,7], k = 3 |
| 16 | + * Output: 3 |
| 17 | + * Explanation: Modify the array from [3,4,<u>5</u>,<u>2</u>,<u>1</u>,7,3,4,7] to [3,4,<u>7</u>,<u>3</u>,<u>4</u>,7,3,4,7]. |
| 18 | + * |
| 19 | + * Example 3: |
| 20 | + * |
| 21 | + * Input: nums = [1,2,4,1,2,5,1,2,6], k = 3 |
| 22 | + * Output: 3 |
| 23 | + * Explanation: Modify the array from [1,2,<u>4,</u>1,2,<u>5</u>,1,2,<u>6</u>] to [1,2,<u>3</u>,1,2,<u>3</u>,1,2,<u>3</u>]. |
| 24 | + * |
| 25 | + * Constraints: |
| 26 | + * |
| 27 | + * 1 <= k <= nums.length <= 2000 |
| 28 | + * 0 <= nums[i] < 2^10 |
| 29 | + * |
| 30 | + */ |
| 31 | +pub struct Solution {} |
| 32 | + |
| 33 | +// problem: https://leetcode.com/problems/make-the-xor-of-all-segments-equal-to-zero/ |
| 34 | +// discuss: https://leetcode.com/problems/make-the-xor-of-all-segments-equal-to-zero/discuss/?currentPage=1&orderBy=most_votes&query= |
| 35 | + |
| 36 | +// submission codes start here |
| 37 | + |
| 38 | +impl Solution { |
| 39 | + pub fn min_changes(nums: Vec<i32>, k: i32) -> i32 { |
| 40 | + 0 |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// submission codes end |
| 45 | + |
| 46 | +#[cfg(test)] |
| 47 | +mod tests { |
| 48 | + use super::*; |
| 49 | + |
| 50 | + #[test] |
| 51 | + #[ignore] |
| 52 | + fn test_1787_example_1() { |
| 53 | + let nums = vec![1, 2, 0, 3, 0]; |
| 54 | + let k = 1; |
| 55 | + |
| 56 | + let result = 3; |
| 57 | + |
| 58 | + assert_eq!(Solution::min_changes(nums, k), result); |
| 59 | + } |
| 60 | + |
| 61 | + #[test] |
| 62 | + #[ignore] |
| 63 | + fn test_1787_example_2() { |
| 64 | + let nums = vec![3, 4, 5, 2, 1, 7, 3, 4, 7]; |
| 65 | + let k = 3; |
| 66 | + |
| 67 | + let result = 3; |
| 68 | + |
| 69 | + assert_eq!(Solution::min_changes(nums, k), result); |
| 70 | + } |
| 71 | + |
| 72 | + #[test] |
| 73 | + #[ignore] |
| 74 | + fn test_1787_example_3() { |
| 75 | + let nums = vec![1, 2, 4, 1, 2, 5, 1, 2, 6]; |
| 76 | + let k = 3; |
| 77 | + |
| 78 | + let result = 3; |
| 79 | + |
| 80 | + assert_eq!(Solution::min_changes(nums, k), result); |
| 81 | + } |
| 82 | +} |
0 commit comments