Tap here to switch tabs
Problem
Ask
Submissions

Problem: Nim Game

med
30 min
Explore the Nim Game problem to understand how to identify winning strategies when players remove stones optimally. This lesson helps you apply mathematical reasoning and pattern recognition to solve game theory questions commonly encountered in coding interviews.

Statement

You and a friend are playing a game called the Nim Game with a heap of stones. The rules are as follows:

  • There is a single heap containing n stones.

  • You and your friend take alternating turns, with you going first.

  • On each turn, the current player must remove between 11 and 33 stones (inclusive) from the heap.

  • The player who removes the last stone wins the game.

Given n, the number of stones in the heap, return TRUE if you can win the game assuming both players play optimally, otherwise return FALSE.

Constraints:

  • 11 \leq n 2311\leq 2^{31} - 1

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Nim Game

med
30 min
Explore the Nim Game problem to understand how to identify winning strategies when players remove stones optimally. This lesson helps you apply mathematical reasoning and pattern recognition to solve game theory questions commonly encountered in coding interviews.

Statement

You and a friend are playing a game called the Nim Game with a heap of stones. The rules are as follows:

  • There is a single heap containing n stones.

  • You and your friend take alternating turns, with you going first.

  • On each turn, the current player must remove between 11 and 33 stones (inclusive) from the heap.

  • The player who removes the last stone wins the game.

Given n, the number of stones in the heap, return TRUE if you can win the game assuming both players play optimally, otherwise return FALSE.

Constraints:

  • 11 \leq n 2311\leq 2^{31} - 1