Magicsheet logo

Determine the Winner of a Bowling Game

Easy
77.4%
Updated 6/1/2025

Asked by 1 Company

Determine the Winner of a Bowling Game

What is this problem about?

The Determine the Winner of a Bowling Game interview question asks you to calculate the scores of two players based on a sequence of rolls. The twist is a special "multiplier" rule: if a player hits 10 pins in any of their previous two turns, their current turn's score is doubled. You need to return 1 if Player 1 wins, 2 if Player 2 wins, or 0 if it's a draw.

Why is this asked in interviews?

DE Shaw uses this "Easy" question to evaluate a candidate's attention to detail and ability to implement a set of rules accurately. It tests your proficiency with simulation interview patterns and array traversal. The logic requires you to maintain a "window" of previous rolls to decide the current multiplier, which is a common task in game logic and financial auditing systems.

Algorithmic pattern used

This problem uses Linear Simulation.

  1. Create a helper function calculateScore(rolls) to avoid code duplication.
  2. In the function, iterate through the array.
  3. For index ii, check if rolls[i-1] == 10 or rolls[i-2] == 10.
  4. If yes, add 2imesrolls[i]2 imes rolls[i] to the total; otherwise, add rolls[i]rolls[i].
  5. Call the function for both players and compare.

Example explanation

Player 1: [5, 10, 3, 2]

  1. 5: total=5.
  2. 10: total=5+10=15.
  3. 3: Previous roll was 10. total=15 + (2*3) = 21.
  4. 2: Two rolls ago was 10. total=21 + (2*2) = 25. Result: 25.

Common mistakes candidates make

  • Index Out of Bounds: Forgetting to check if i1i-1 or i2i-2 are valid indices before accessing the array.
  • Accumulating Multipliers: Thinking that two 10s in a row triple or quadruple the score. The rule usually states the score is just "doubled" if any of the previous two were 10.
  • Resetting incorrectly: Failing to clear the "double score" effect after two turns.

Interview preparation tip

Modularize your code. Even for simple problems, separating the "Scoring Logic" into its own function makes the main "Comparison Logic" much cleaner and reduces bugs.

Similar Questions