# LC 2660. Determine the Winner of a Bowling Game ### [Problem link](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game/) ###### tags: `leedcode` `easy` `python` You are given two **0-indexed** integer arrays <code><font face="monospace">player1</font></code> and <code>player2</code>, that represent the number of pins that player 1 and player 2 hit in a bowling game, respectively. The bowling game consists of <code>n</code> turns, and the number of pins in each turn is exactly <code>10</code>. Assume a player hit <code>x<sub>i</sub></code> pins in the <code>i<sup>th</sup></code> turn. The value of the <code>i<sup>th</sup></code> turn for the player is: - <code>2x<sub>i</sub></code> if the player hit <code>10</code> pins in any of the previous two turns. - Otherwise, It is <code>x<sub>i</sub></code>. The score of the player is the sum of the values of their <code>n</code> turns. Return - <code>1</code> if the score of player 1 is more than the score of player 2, - <code>2</code> if the score of player 2 is more than the score of player 1, and - <code>0</code> in case of a draw. **Example 1:** ``` Input: player1 = [4,10,7,9], player2 = [6,5,2,3] Output: 1 Explanation: The score of player1 is 4 + 10 + 2*7 + 2*9 = 46. The score of player2 is 6 + 5 + 2 + 3 = 16. Score of player1 is more than the score of player2, so, player1 is the winner, and the answer is 1. ``` **Example 2:** ``` Input: player1 = [3,5,7,6], player2 = [8,10,10,2] Output: 2 Explanation: The score of player1 is 3 + 5 + 7 + 6 = 21. The score of player2 is 8 + 10 + 2*10 + 2*2 = 42. Score of player2 is more than the score of player1, so, player2 is the winner, and the answer is 2. ``` **Example 3:** ``` Input: player1 = [2,3], player2 = [4,1] Output: 0 Explanation: The score of player1 is 2 + 3 = 5 The score of player2 is 4 + 1 = 5 The score of player1 equals to the score of player2, so, there is a draw, and the answer is 0. ``` **Constraints:** - <code>n == player1.length == player2.length</code> - <code>1 <= n <= 1000</code> - <code>0 <= player1[i], player2[i] <= 10</code> ## Solution 1 #### Python ```python= class Solution: def isWinner(self, player1: List[int], player2: List[int]) -> int: res = 0 def calScore(scores): bonus = 0 if len(scores) >= 2 and scores[0] == 10: bonus += scores[1] for i in range(2, len(scores)): if scores[i - 1] == 10 or scores[i - 2] == 10: bonus += scores[i] return sum(scores) + bonus s1 = calScore(player1) s2 = calScore(player2) if s1 > s2: res = 1 elif s1 < s2: res = 2 else: res = 0 return res ``` >### Complexity >n = player1.length = player2.length >| | Time Complexity | Space Complexity | >| ----------- | --------------- | ---------------- | >| Solution 1 | O(n) | O(1) | ## Note x