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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 598ms, memory 31.8MB, accepted 2026-01-01.
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')