Find the Winning Player in Coin Game - Problem

Alice and Bob are playing an exciting strategic coin game where each player must collect exactly 115 points worth of coins on their turn!

You have two types of coins available:

  • Gold coins: Worth 75 points each (you have x of these)
  • Silver coins: Worth 10 points each (you have y of these)

Game Rules:

  1. Alice goes first, then players alternate turns
  2. On each turn, a player must pick coins that total exactly 115 points
  3. The first player who cannot make exactly 115 points loses the game
  4. Both players play optimally (they make the best possible moves)

Your task is to determine who wins this strategic battle! ๐ŸŽฏ

Key insight: To make 115 points, a player can use a gold coins (75 each) and b silver coins (10 each) where 75a + 10b = 115

Input & Output

example_1.py โ€” Basic Case
$ Input: x = 2, y = 8
โ€บ Output: Alice
๐Ÿ’ก Note: Alice can make 2 turns (using all coins: 2 gold + 8 silver), Bob can make 0 turns. Since Alice makes the last move, she wins.
example_2.py โ€” Bob Wins
$ Input: x = 4, y = 11
โ€บ Output: Bob
๐Ÿ’ก Note: Max turns = min(4, 11รท4) = min(4, 2) = 2. Since 2 is even, Bob makes the last move and wins.
example_3.py โ€” Edge Case
$ Input: x = 1, y = 3
โ€บ Output: Bob
๐Ÿ’ก Note: Not enough silver coins! Need 4 silver per turn but only have 3. Max turns = min(1, 3รท4) = min(1, 0) = 0. Alice cannot move, so Bob wins immediately.

Visualization

Tap to expand
Coin Game Visualization$75$75$75...$10$10$10$10...Gold Coins (x)Silver Coins (y)Each Turn Requirement: Exactly $115$75+4 ร— $10 = $40= $115 โœ“Turn CalculationMax turns =min(x, y รท 4)Limited by whichevercoin type runs out firstWinner DeterminationIf turns is ODD:Alice winsIf turns is EVEN:Bob wins
Understanding the Visualization
1
Setup
Start with x gold coins ($75 each) and y silver coins ($10 each)
2
Valid Moves
Only one way to make $115: take 1 gold + 4 silver coins
3
Count Turns
Calculate maximum possible turns: min(x, yรท4)
4
Determine Winner
Odd total turns = Alice wins, Even total turns = Bob wins
Key Takeaway
๐ŸŽฏ Key Insight: The equation 75a + 10b = 115 has only one integer solution: a=1, b=4. This makes the game predictable - each turn always consumes exactly 1 gold and 4 silver coins!

Time & Space Complexity

Time Complexity
โฑ๏ธ
O(1)

Just a few arithmetic operations regardless of input size

n
2n
โœ“ Linear Growth
Space Complexity
O(1)

Only uses a constant amount of extra variables

n
2n
โœ“ Linear Space

Constraints

  • 1 โ‰ค x, y โ‰ค 105
  • Both x and y are positive integers
  • Each turn must total exactly 115 points
Asked in
Google 28 Amazon 22 Meta 18 Microsoft 15
42.6K Views
Medium Frequency
~12 min Avg. Time
1.8K 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