Stone Removal Game - Problem

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.

Input & Output

Example 1 — Small Pile
$ Input: n = 10
Output: true
💡 Note: Alice removes 10 stones and wins immediately since Bob cannot make any move (pile is empty).
Example 2 — Medium Pile
$ Input: n = 25
Output: false
💡 Note: Alice removes 10 (15 left), Bob removes 9 (6 left), Alice needs 8 but only 6 available. Alice loses.
Example 3 — Large Pile
$ Input: n = 100
Output: true
💡 Note: After several rounds: Alice=10+8+6+4+2=30, Bob=9+7+5+3+1=25. Alice can make more complete moves.

Constraints

  • 1 ≤ n ≤ 105

Visualization

Tap to expand
Stone Removal Game INPUT Stone Pile (n = 10) 1 2 3 4 5 6 7 8 9 10 n = 10 Total stones in pile Alice Goes first Bob Goes second ALGORITHM STEPS 1 Alice's Turn Removes 10 stones Remaining: 10-10 = 0 2 Bob's Turn Should remove 9 But 0 stones left! 3 Check Winner Bob cannot move 0 < 9 (required) 4 Result Bob loses Alice wins! Game Simulation Turn Player Remove Left 1 Alice 10 0 2 Bob 9 X FINAL RESULT ALICE WINS Output: true Alice removes all 10 stones in her first turn. Bob cannot make a move. Key Insight: The removal sequence is 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 (decreasing by 1 each turn). Total stones needed for full game: 10+9+8+...+1 = 55. With n=10, Alice takes all stones immediately, leaving Bob unable to play. Formula: Check if n allows Alice's cumulative moves. TutorialsPoint - Stone Removal Game | Optimal Solution
Asked in
Google 15 Amazon 12 Microsoft 8
12.5K Views
Medium Frequency
~15 min Avg. Time
234 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen