Problem
Ask
Submissions

Problem: Nim Game

Medium
30 min
Explore the Nim Game problem to understand how to determine a winning strategy with optimal moves. Learn to analyze this classic game scenario by assessing problem constraints and applying mathematical reasoning to devise a solution that predicts if you can win given the number of stones. This lesson helps you develop problem-solving skills relevant to coding interviews involving math patterns and strategic gameplay.

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

Problem
Ask
Submissions

Problem: Nim Game

Medium
30 min
Explore the Nim Game problem to understand how to determine a winning strategy with optimal moves. Learn to analyze this classic game scenario by assessing problem constraints and applying mathematical reasoning to devise a solution that predicts if you can win given the number of stones. This lesson helps you develop problem-solving skills relevant to coding interviews involving math patterns and strategic gameplay.

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