#3222
Easy Algorithms Find the winning player in coin game
Math Simulation Game Theory
53.1% acceptance
Feb 25, 2026
128
15
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 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.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn winning_player(x: i32, y: i32) -> String {
// Each turn uses 1 coin of 75 and 4 coins of 10 (75 + 4*10 = 115)
let turns = x.min(y / 4);
if turns % 2 == 1 {
"Alice".to_string()
} else {
"Bob".to_string()
}
}
}