LeetCode solutions

3249. Minimum Number of Operations to Make Array XOR Equal to K

My accepted Python solution to LeetCode problem 3249, Minimum Number of Operations to Make Array XOR Equal to K, running in 598ms.

  • Difficulty: Medium
  • Python
  • Runtime 598ms
  • Memory 31.8MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 598ms, memory 31.8MB, accepted 2026-01-01.

python
class Solution:
    def minOperations(self, nums: List[int], k: int) -> int:
        xor_all = 0
        for num in nums:
            xor_all ^= num
        
        diff = xor_all ^ k
        return bin(diff).count('1')

Source