Tap here to switch tabs
Problem
Submissions

Problem: Stone Game IV

med
30 min
Try to solve the Stone Game IV problem.

Statement

Alice and Bob take turns playing a game, with Alice taking the first turn. Initially, there are n stones in a pile.

On each turn, the current player must remove a positive square number of stones from the pile. A player loses the game if they cannot make a valid move on their turn.

Assuming both players play optimally, return true if Alice wins the game, or false otherwise.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Stone Game IV

med
30 min
Try to solve the Stone Game IV problem.

Statement

Alice and Bob take turns playing a game, with Alice taking the first turn. Initially, there are n stones in a pile.

On each turn, the current player must remove a positive square number of stones from the pile. A player loses the game if they cannot make a valid move on their turn.

Assuming both players play optimally, return true if Alice wins the game, or false otherwise.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5