Determine the Winner of a Bowling Game - Problem
Bowling Championship Simulator

Welcome to the digital bowling alley! ๐ŸŽณ You're tasked with determining the winner of a special bowling game between two players.

In this unique bowling variant:
โ€ข Each game consists of n turns
โ€ข Each turn has exactly 10 pins available
โ€ข Players can hit anywhere from 0 to 10 pins per turn

The Scoring Twist: If a player hits 10 pins (a strike) in either the previous turn (i-1) or two turns ago (i-2), their current turn's score gets doubled!

Your Mission: Calculate both players' total scores and determine:
โ€ข Return 1 if Player 1 wins
โ€ข Return 2 if Player 2 wins
โ€ข Return 0 if it's a tie

Can you build the perfect scoring system? ๐Ÿ†

Input & Output

example_1.py โ€” Basic Strike Bonus
$ Input: player1 = [4,10,7,9], player2 = [6,5,10,4]
โ€บ Output: 1
๐Ÿ’ก Note: Player 1 scores: 4 + 10 + (7ร—2) + (9ร—2) = 46. Player 2 scores: 6 + 5 + 10 + (4ร—2) = 29. Player 1 wins!
example_2.py โ€” Equal Scores
$ Input: player1 = [3,5,7,6], player2 = [8,10,10,2]
โ€บ Output: 2
๐Ÿ’ก Note: Player 1 scores: 3 + 5 + 7 + 6 = 21. Player 2 scores: 8 + 10 + 10 + (2ร—2) = 32. Player 2 wins!
example_3.py โ€” Two Turns Back Strike
$ Input: player1 = [2,3], player2 = [4,1]
โ€บ Output: 0
๐Ÿ’ก Note: Player 1 scores: 2 + 3 = 5. Player 2 scores: 4 + 1 = 5. It's a tie!

Visualization

Tap to expand
๐ŸŽณ Bowling Championship ScorerPlayer 1 Scoreboard44 pts1010 ptsโšก714 pts2x918 pts2xTotal: 46Player 2 Scoreboard66 pts55 pts1010 ptsโšก48 pts2xTotal: 29๐Ÿ† Player 1 Wins!
Understanding the Visualization
1
Track Each Turn
Process each player's turns sequentially
2
Check Strike History
Look back 1-2 turns for strikes (10 pins)
3
Apply Bonus
Double current score if recent strikes found
4
Determine Winner
Compare final totals
Key Takeaway
๐ŸŽฏ Key Insight: Track the last two turns to efficiently apply strike bonuses in O(n) time - no complex data structures needed!

Time & Space Complexity

Time Complexity
โฑ๏ธ
O(n)

We iterate through each turn once, checking previous turns takes constant time

n
2n
โœ“ Linear Growth
Space Complexity
O(1)

Only using variables to track scores, no additional data structures

n
2n
โœ“ Linear Space

Constraints

  • n == player1.length == player2.length
  • 1 โ‰ค n โ‰ค 1000
  • 0 โ‰ค player1[i], player2[i] โ‰ค 10
Asked in
Amazon 15 Google 12 Microsoft 8 Meta 6
24.4K Views
Medium Frequency
~12 min Avg. Time
847 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen