Determine the Winner of a Bowling Game

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 i^th turn. The value of the i^th turn for the player is:

  • 2xi if the player hits 10 pins in either (i - 1)^th or (i - 2)^th turn.
  • Otherwise, it is xi.

The score of the player is the sum of the values of their n turns.

Return:

  • 1 if the score of player 1 is more than the score of player 2,
  • 2 if the score of player 2 is more than the score of player 1, and
  • 0 in case of a draw.
Example 1
Inputplayer1 = [5,10,3,2], player2 = [6,5,7,3]
Output1
The score of player 1 is 5 + 10 + 2*3 + 2*2 = 25, while the score of player 2 is 6 + 5 + 7 + 3 = 21.
Example 2
Inputplayer1 = [3,5,7,6], player2 = [8,10,10,2]
Output2
The score of player 1 is 3 + 5 + 7 + 6 = 21, while the score of player 2 is 8 + 10 + 2*10 + 2*2 = 42.

Constraints

  • n == player1.length == player2.length
  • 1 <= n <= 1000
  • 0 <= player1[i], player2[i] <= 10

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate