Skip to content

Practice Make the XOR of All Segments Equal to Zero

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

Hard#1787
LeetCode Problem

Make the XOR of All Segments Equal to Zero

Problem Statement

You are given an array nums​​​ and an integer k​​​​​. The XOR 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]. 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.

Source: Make the XOR of All Segments Equal to Zero on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,0,3,0], k = 1
Output
3

# Example 2

Input
nums = [3,4,5,2,1,7,3,4,7], k = 3
Output
3

# Example 3

Input
nums = [1,2,4,1,2,5,1,2,6], k = 3
Output
3

Constraints

1 <= k <= nums.length <= 2000
​​​​​​0 <= nums[i] < 2^10

Related LeetCode Problems

Practice more problems similar to Make the XOR of All Segments Equal to Zero.

Review your practice with PhantomCodeAI

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