Tap here to switch tabs
Problem
Submissions

Problem: Game of Nim

Try to solve the Game of Nim problem.

Statement

Alice and Bob are playing a game with several piles of stones. You are given an integer array piles, where piles[i] denotes the number of stones in the iith pile.

Alice and Bob take turns, with Alice making the first move. On each turn, a player chooses any non empty pile and removes any positive number of stones from that pile. The game ends when all piles are empty. The player who cannot make a move loses the game.

Assuming both players play optimally, return true if Alice wins the game, or false otherwise.

Constraints:

  • n == piles.length

  • 1≤1 \leq n ≤7\leq 7

  • 1≤1 \leq piles[i] ≤7\leq 7

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Game of Nim

Try to solve the Game of Nim problem.

Statement

Alice and Bob are playing a game with several piles of stones. You are given an integer array piles, where piles[i] denotes the number of stones in the iith pile.

Alice and Bob take turns, with Alice making the first move. On each turn, a player chooses any non empty pile and removes any positive number of stones from that pile. The game ends when all piles are empty. The player who cannot make a move loses the game.

Assuming both players play optimally, return true if Alice wins the game, or false otherwise.

Constraints:

  • n == piles.length

  • 1≤1 \leq n ≤7\leq 7

  • 1≤1 \leq piles[i] ≤7\leq 7