Bowling Frame Scores
Updated
Problem statement
Process events for one player's ten-frame bowling game. Each event is one of the following:
[0, pins]: ROLL records the number of pins knocked down by the next roll.[1, frame]: SCORE asks for the score of frameframeand the cumulative score through that frame. Frames are numbered 1 through 10.
Frames 1 through 9 start with ten pins. A first roll of 10 is a strike and ends the frame immediately. Otherwise, the player takes a second roll, which can knock down at most the pins still standing. Those two regular rolls end the frame. If their sum is 10, the frame is a spare. Otherwise, it is an open frame.
Calculate each frame's score from the raw roll values:
- A strike scores 10 plus the next two rolls, even when those rolls cross a frame boundary.
- A spare scores 10 plus the next one roll.
- An open frame scores the sum of its two regular rolls.
Do not add a following frame's bonus-inclusive score. For example, a strike followed by rolls 7 and 3 scores 20, even if the following spare later receives its own bonus.
Frame 10 also starts with ten pins. If its first roll is not a strike, its second regular roll can knock down at most the remaining pins. An open tenth frame ends after those two rolls. A spare gets one extra roll from a fresh set of ten pins. A strike gets two extra rolls: the first uses a fresh set of ten pins; if it knocks down all ten, the second also uses a fresh set, otherwise the second uses only the pins left standing by the first extra roll.
Use the same scoring formulas for frame 10. Its extra rolls count as raw rolls for scoring. They do not start frames 11 or 12, and they do not earn further extra rolls, even if they knock down all ten pins.
A frame's score is known only when all of its regular rolls and required bonus rolls have arrived. For each SCORE event, return [frameScore, cumulativeScore] if the requested frame's score is known. The cumulative score is the sum of frames 1 through the requested frame. If the frame has not started, is incomplete, or is still waiting for a bonus roll, return [-1, -1]. Under valid input, a known requested frame also has all previous frame scores known.
Queries may appear before the first roll, between rolls, or after the game ends. Repeated queries do not change the game. Once a frame's score is known, it never changes. ROLL events produce no output. Return one independent pair per SCORE event, in event order. With no SCORE events, return an empty array.
Ignoring SCORE events, the rolls form a valid prefix of one game under these rules. The prefix may stop anywhere, including during frame 10's extra rolls. No ROLL appears after the game is complete. Do not change events. Each function call starts a fresh game and returns its own result.
Function
bowlingFrameScores(events: int[][]) → int[][]Examples
Example 1
events = [[0,7],[0,3],[0,5],[0,3],[1,1],[1,2]]return = [[15,15],[8,23]]Rolls 7 and 3 make frame 1 a spare. Its next roll is 5, so its score is 10 + 5 = 15. Frame 2 is open with 5 + 3 = 8 points.
The query for frame 1 returns [15,15]. The query for frame 2 returns [8,23], since 15 + 8 = 23.
Example 2
events = [[0,3],[0,3],[0,1],[0,0],[0,10],[0,7],[0,3],[0,5],[0,2],[1,1],[1,2],[1,3],[1,4],[1,5]]return = [[6,6],[1,7],[20,27],[15,42],[7,49]]The first two frames are open: 3 + 3 = 6 and 1 + 0 = 1. Frame 3 is a strike. Its next two raw rolls are 7 and 3, so it scores 10 + 7 + 3 = 20.
Frame 4 is a spare with next-roll bonus 5, so it scores 15. Frame 5 is open with 5 + 2 = 7. The five cumulative scores are 6, 7, 27, 42 and 49. Frame 3 uses the raw 7 and 3; it does not add frame 4's bonus-inclusive score of 15.
Example 3
events = [[1,1],[0,10],[1,1],[0,4],[1,1],[0,3],[1,1],[1,2]]return = [[-1,-1],[-1,-1],[-1,-1],[17,17],[7,24]]The first query is pending because frame 1 has not started. After the strike, two bonus rolls are still missing. After the next roll of 4, one bonus roll is still missing. These three queries return [-1,-1].
The next roll of 3 completes the strike bonus and also completes frame 2. Frame 1 scores 10 + 4 + 3 = 17. Frame 2 scores 4 + 3 = 7, for a cumulative score of 24. The final two queries return [17,17] and [7,24].
Constraints
0 <= events.length <= 60.- Each event contains exactly 2 integers.
- Every integer in
eventsis between 0 and 10, inclusive. - Each event is either
[0, pins]with0 <= pins <= 10, or[1, frame]with1 <= frame <= 10. - The ROLL subsequence is a valid prefix of one ten-frame game under the stated pin and extra-roll rules. It contains at most 21 rolls and no roll after completion.
More Akuna Capital Phone Screen questions
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Sep 2026
- Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
- Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
- Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
- Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
- Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
- Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025
Similar questions at other companies
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- 2D Convolution Layer Forward PassWaymo · PHONE SCREENWaymo interview questions
- Concurrent Discounted Card PurchasesBrex · PHONE SCREEN
- Ordered IP FirewallDatabricks · PHONE SCREENDatabricks interview questions
- Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
- Generic Stack Operation SequenceArista Networks · PHONE SCREEN · ONSITE INTERVIEWArista Networks interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)