Skip to content

Practice Chalkboard XOR Game

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

Hard#810
LeetCode Problem

Chalkboard XOR Game

Problem Statement

You are given an array of integers nums represents the numbers written on a chalkboard. Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become 0, then that player loses. The bitwise XOR of one element is that element itself, and the bitwise XOR of no elements is 0. Also, if any player starts their turn with the bitwise XOR of all the elements of the chalkboard equal to 0, then that player wins. Return true if and only if Alice wins the game, assuming both players play optimally.

Source: Chalkboard XOR Game on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,1,2]
Output
false

# Example 2

Input
nums = [0,1]
Output
true

# Example 3

Input
nums = [1,2,3]
Output
true

Constraints

1 <= nums.length <= 1000
0 <= nums[i] < 2^16

Related LeetCode Problems

Practice more problems similar to Chalkboard XOR Game.

Review your practice with PhantomCodeAI

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