Skip to content

Practice Minimum Number of Operations to Make Array XOR Equal to K

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

Medium#2997
LeetCode Problem

Minimum Number of Operations to Make Array XOR Equal to K

Problem Statement

Given nums and a positive integer k, one operation flips one bit of any element: 0 becomes 1 or 1 becomes 0. Leading zero bits may also be flipped. Return the fewest operations needed to make the XOR of all array elements equal to k.

Source: Minimum Number of Operations to Make Array XOR Equal to K on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

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

Constraints

1 <= nums.length <= 10^5
0 <= nums[i] <= 10^6
0 <= k <= 10^6

Related LeetCode Problems

Practice more problems similar to Minimum Number of Operations to Make Array XOR Equal to K.

Review your practice with PhantomCodeAI

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