Class Solution
java.lang.Object
g1701_1800.s1787_make_the_xor_of_all_segments_equal_to_zero.Solution
1787 - Make the XOR of All Segments Equal to Zero.<p>Hard</p>
<p>You are given an array <code>nums</code> and an integer <code>k</code>. The XOR of a segment <code>[left, right]</code> where <code>left <= right</code> is the <code>XOR</code> of all the elements with indices between <code>left</code> and <code>right</code>, inclusive: <code>nums[left] XOR nums[left+1] XOR ... XOR nums[right]</code>.</p>
<p>Return <em>the minimum number of elements to change in the array</em> such that the <code>XOR</code> of all segments of size <code>k</code> is equal to zero.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,2,0,3,0], k = 1</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> Modify the array from [<strong>1</strong> , <strong>2</strong> ,0, <strong>3</strong> ,0] to from [<strong>0</strong> , <strong>0</strong> ,0, <strong>0</strong> ,0].</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [3,4,5,2,1,7,3,4,7], k = 3</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> Modify the array from [3,4, <strong>5</strong> , <strong>2</strong> , <strong>1</strong> ,7,3,4,7] to [3,4, <strong>7</strong> , <strong>3</strong> , <strong>4</strong> ,7,3,4,7].</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [1,2,4,1,2,5,1,2,6], k = 3</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> Modify the array from [1,2, **4, **1,2, <strong>5</strong> ,1,2, <strong>6</strong> ] to [1,2, <strong>3</strong> ,1,2, <strong>3</strong> ,1,2, <strong>3</strong> ].</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= k <= nums.length <= 2000</code></li>
<li><code>0 <= nums[i] < 2<sup>10</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minChanges
public int minChanges(int[] nums, int k)
-