Skip to content

Practice Stone Game IV

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

Hard#1510
LeetCode Problem

Stone Game IV

Problem Statement

Alice and Bob take turns playing a game, with Alice starting first. Initially, there are n stones in a pile. On each player's turn, that player makes a move consisting of removing any non-zero square number of stones in the pile. Also, if a player cannot make a move, he/she loses the game. Given a positive integer n, return true if and only if Alice wins the game otherwise return false, assuming both players play optimally.

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

Examples

# Example 1

Input
n = 1
Output
true

# Example 2

Input
n = 2
Output
false

# Example 3

Input
n = 4
Output
true

Constraints

1 <= n <= 10^5

Related LeetCode Problems

Practice more problems similar to Stone Game IV.

Review your practice with PhantomCodeAI

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