Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 1.26 KB

_1535. Find the Winner of an Array Game.md

File metadata and controls

49 lines (37 loc) · 1.26 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 08, 2024

Last updated : July 01, 2024


Related Topics : Array, Simulation

Acceptance Rate : 56.79 %


Solutions

Python

# Did this one cause apparently it was very close tot he BW 132 contest q2 and it was lol
class Solution:
    def getWinner(self, arr: List[int], k: int) -> int:
        wins = {}
        playerQueue = deque(arr)

        king = playerQueue.popleft()
        counter = 0
        while wins.get(king, 0) < k :
            if counter == len(arr) :
                break
            counter += 1

            if king > playerQueue[0] :
                wins[king] = wins.get(king, 0) + 1
                playerQueue.append(playerQueue.popleft())
            else :
                playerQueue.append(king)
                king = playerQueue.popleft()
                wins[king] = 1
        return king