Bowling Scoring

Calculate the score of a bowling game.

Medium6/1/2024

Problem statement

Given an array of integers representing the number of pins knocked down in each frame of a bowling game, return the total score for the game.

A bowling game consists of 10 frames, in each frame the player has two opportunities to knock down 10 pins. The score for the frame is the total number of pins knocked down, plus bonuses for strikes and spares.

  • Strike: A strike is when the player knocks down all 10 pins on the first roll. The frame is then completed with a single roll. The bonus for that frame is the value of the next two rolls.
  • Spare: A spare is when the player knocks down all 10 pins in two rolls. The bonus for that frame is the value of the next roll.

In the tenth frame a player who rolls a spare or strike is allowed to roll the extra balls to complete the frame. However no more than three balls can be rolled in the tenth frame.

Example: For the following frames:

[[10],[7,3],[9,0],[10],[0,8],[8,2],[0,6],[10],[10],[10,8,1]]

The score should be 167.

Problem leaderboard

#
Size
%
Users
#1
79 c.
Top 17%
Steffan
#2
82 c.
Top 33%
madeforlosers
#3
107 c.
Top 50%
KrausRaus
#4
165 c.
Top 67%
Thomasdcrt
#5
179 c.
Top 83%
maximec-indy
#6
569 c.
Top 100%
ComputerKWasTaken