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
75points each (you havexof these) - Silver coins: Worth
10points each (you haveyof these)
Game Rules:
- Alice goes first, then players alternate turns
- On each turn, a player must pick coins that total exactly
115points - The first player who cannot make exactly
115points loses the game - 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
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
โ Linear Growth
Space Complexity
O(1)
Only uses a constant amount of extra variables
โ Linear Space
Constraints
- 1 โค x, y โค 105
- Both x and y are positive integers
- Each turn must total exactly 115 points
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code