Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find the Winning Player in Coin Game

XPChallenge Points: 10
levelLevel: Easy

You have x coins of value 75 and y coins of value 10. Players Alice (first) and Bob alternate turns.
On each turn a player must pick coins whose total value is exactly 115. If a player cannot do so on their turn, they lose.
Assuming optimal play, return "Alice" or "Bob" indicating the winner.

Key insight:
To make 115 using only 75s and 10s, the equation is 75a + 10b = 115.
Dividing by 5 ⇒ 15a + 2b = 23. The only non-negative integer solution is a = 1, b = 4.
So each valid move consumes 1×75 coin and 4×10 coins. The number of possible moves is:

t = min(x // 1, y // 4) = min(x, y // 4)
  • If t = 0, Alice cannot move → Bob wins.

  • Otherwise, players take exactly one “pack” per turn; Alice wins iff t is odd.

Example 1:

Input: x = 4, y = 11

Output: "Bob"

Explanation:

t = min(4, 11//4) = min(4, 2) = 2 (even). Alice makes one turn (1×75 + 4×10), Bob makes the second. No packs remain; Alice’s next turn has no move → Bob wins.

Example 2:

Input: x = 2, y = 7

Output: "Alice"

Explanation:

Possible full turns t = min(2, 7//4) = min(2, 1) = 1 (odd). Alice makes the only turn: 1×75 + 4×10. Bob then cannot move → Alice wins.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result