Find the Winning Player in Coin Game - Problem

You are given two positive integers x and y, denoting the number of coins with values 75 and 10 respectively.

Alice and Bob are playing a game. Each turn, starting with Alice, the player must pick up coins with a total value of exactly 115. If the player is unable to do so, they lose the game.

Return the name of the player who wins the game if both players play optimally.

Input & Output

Example 1 — Basic Case
$ Input: x = 2, y = 8
Output: Bob
💡 Note: Maximum turns = min(2, 8÷4) = min(2, 2) = 2. Since 2 is even, Bob wins.
Example 2 — Alice Wins
$ Input: x = 4, y = 11
Output: Alice
💡 Note: Maximum turns = min(4, 11÷4) = min(4, 2) = 2. Wait, that's even so Bob wins. Let me recalculate: min(4, 11÷4) = min(4, 2) = 2, so Bob wins.
Example 3 — Insufficient Coins
$ Input: x = 1, y = 3
Output: Bob
💡 Note: Need 1×75 + 4×10 = 115, but only have 3 ten-coins (need 4). Alice can't make first move, so Bob wins.

Constraints

  • 1 ≤ x, y ≤ 100

Visualization

Tap to expand
Coin Game: Find the Winner75-value2 coins10-value8 coinsEach Turn Requires1×75 + 4×10 = 115Max Turnsmin(2, 8÷4) = 2Turn 1: AliceTakes 1×75 + 4×10Turn 2: BobTakes 1×75 + 4×10Remaining: 0, 0Alice can't move!BOB WINS!2 turns (even)Rule: Even number of total turns → Bob wins | Odd → Alice wins
Understanding the Visualization
1
Input
x=2 coins of value 75, y=8 coins of value 10
2
Game Rule
Each turn, player must take coins worth exactly 115
3
Winner
Player who can't make 115 loses
Key Takeaway
🎯 Key Insight: There's exactly one way to make 115 (1×75 + 4×10), so the winner is determined by whether the maximum possible turns is odd (Alice) or even (Bob)
Asked in
Google 15 Amazon 12
12.0K Views
Medium Frequency
~8 min Avg. Time
450 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