Skip to main content
Back to problems
#3360
Easy Algorithms

Stone removal game

Math Simulation
42.4% acceptance
Feb 24, 2026
68
5
Alice and Bob are playing a game where they take turns removing stones from a pile, with Alice going first. Alice starts by removing exactly 10 stones on her first turn. For each subsequent turn, each player removes exactly 1 fewer stone than the previous opponent. The player who cannot make a move loses the game. Given a positive integer n, return true if Alice wins the game and false otherwise.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn can_alice_win(n: i32) -> bool {
    // Alice removes 10, Bob removes 9, Alice removes 8, Bob removes 7, ...
    // Sequence: 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
    // Alice wins if she can make a move but Bob can't (or Bob runs out of stones)
    let mut stones = n;
    let mut remove = 10;
    let mut alice_turn = true;
    while stones >= remove {
      stones -= remove;
      remove -= 1;
      alice_turn = !alice_turn;
    }
    // Current player (alice_turn reflects who cannot move) = loser
    // If alice_turn is now true, alice cannot move -> alice loses
    // If alice_turn is now false, bob cannot move -> alice wins
    !alice_turn
  }
}