Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Nim Game

XPChallenge Points: 10
levelLevel: Easy

You and your friend are playing a simple Nim Game:
• There is a single heap of stones on the table.
• You and your friend take turns, with you going first.
• On each turn, a player can remove 1 to 3 stones from the heap.
• The player who removes the last stone wins the game.
Given an integer n, representing the number of stones, return true if you can guarantee a win assuming both players play optimally, otherwise return false.

Example 1:

Input: n = 4

Output: false

Example 2:

Input: n = 1

Output: true

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result