Calculate Bowling Game Score
Company: Tradedesk
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's ability to implement rule-based scoring logic, array processing, and stateful iteration to correctly aggregate frame scores in ten-pin bowling.
Constraints
- rolls represents a valid complete ten-pin bowling game
- 11 <= len(rolls) <= 21
- 0 <= rolls[i] <= 10
- The game contains exactly 10 frames, including any valid bonus rolls in the 10th frame
Examples
Input: ([10, 7, 3, 9, 0, 10, 0, 8, 8, 2, 0, 6, 10, 10, 10, 8, 1],)
Expected Output: 167
Explanation: The game includes strikes, spares, and open frames. Applying strike and spare bonuses over all 10 frames gives a total score of 167.
Input: ([10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],)
Expected Output: 300
Explanation: A perfect game has 12 strikes. Each frame scores 30, for a total of 300.
Input: ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],)
Expected Output: 0
Explanation: No pins are knocked down in any roll, so every frame scores 0.
Input: ([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],)
Expected Output: 20
Explanation: There are 10 open frames, each worth 2 points.
Input: ([5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],)
Expected Output: 150
Explanation: Every frame is a spare with a bonus roll of 5, so each frame scores 15.
Hints
- Process exactly 10 frames, while keeping an index into the rolls list.
- For strikes and spares, the bonus rolls are already present later in the rolls list, so you can look ahead from the current index.