All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 08, 2024
Last updated : July 01, 2024
Related Topics : Array, Simulation
Acceptance Rate : 56.79 %
# 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