Chalkboard XOR Game

You are given an array of integers nums representing 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.

Example 1
Inputnums = [1,1,2]
Outputfalse
Alice loses whether she erases 1 or 2, because Bob can force Alice to be the player who loses.
Example 2
Inputnums = [0,1]
Outputtrue
Alice wins with optimal play for nums = [0, 1].

Constraints

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

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate