Skip to content

Practice Nim Game

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

Easy#292
LeetCode Problem

Nim Game

Problem Statement

A heap contains n stones. You and a friend alternate turns, with you moving first. On each turn, remove one, two, or three stones; whoever removes the last stone wins. Assuming both players choose their moves optimally, return true if you can force a win and false otherwise.

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

Examples

# Example 1

Input
n = 4
Output
false

# Example 2

Input
n = 1
Output
true

# Example 3

Input
n = 2
Output
true

Constraints

1 <= n <= 2^31 - 1

Related LeetCode Problems

Practice more problems similar to Nim Game.

Review your practice with PhantomCodeAI

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