Determine the Winner of a Bowling Game - Problem
You are given two 0-indexed integer arrays player1 and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively.
The bowling game consists of n turns, and the number of pins in each turn is exactly 10.
Assume a player hits xi pins in the ith turn. The value of the ith turn for the player is:
2xiif the player hits 10 pins in either(i - 1)thor(i - 2)thturn.- Otherwise, it is
xi.
The score of the player is the sum of the values of their n turns.
Return:
1if the score of player 1 is more than the score of player 2,2if the score of player 2 is more than the score of player 1, and0in case of a draw.
Input & Output
Example 1 — Basic Strike Bonus
$
Input:
player1 = [4,10,7,9], player2 = [3,5,7,6]
›
Output:
1
💡 Note:
Player1: 4 + 10 + 14 (7*2 due to strike) + 9 = 37. Player2: 3 + 5 + 7 + 6 = 21. Player1 wins, return 1.
Example 2 — Tie Game
$
Input:
player1 = [3,5,7,6], player2 = [8,10,10,2]
›
Output:
2
💡 Note:
Player1: 3 + 5 + 7 + 6 = 21. Player2: 8 + 10 + 20 (10*2 due to strike) + 4 (2*2 due to strike) = 42. Player2 wins, return 2.
Example 3 — Multiple Strikes
$
Input:
player1 = [2,3], player2 = [4,1]
›
Output:
0
💡 Note:
Player1: 2 + 3 = 5. Player2: 4 + 1 = 5. It's a tie, return 0.
Constraints
- 1 ≤ player1.length, player2.length ≤ 1000
- 0 ≤ player1[i], player2[i] ≤ 10
Visualization
Tap to expand
Understanding the Visualization
1
Input Arrays
Two players with their pin counts per turn
2
Apply Strike Rules
Double the value if previous 1-2 turns had strikes (10 pins)
3
Compare Scores
Return 1 if player1 wins, 2 if player2 wins, 0 for tie
Key Takeaway
🎯 Key Insight: A strike (10 pins) doubles the value of the next 1-2 turns, significantly impacting the final score
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code