Find the Winning Player in Coin Game

EasyMathSimulationGame Theory

Solution

export function losingPlayer(x: number, y: number): string {
  const turn = Math.min(x, Math.floor(y / 4));
  return turn % 2 === 1 ? 'Alice' : 'Bob';
}

Complexity

  • Time: O(1)
  • Space: O(1)