Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.56 KB

_3175. Find The First Player to win K Games in a Row.md

File metadata and controls

53 lines (39 loc) · 1.56 KB

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

Completed during Biweekly Contest 132 (q2)

Back to top


First completed : July 07, 2024

Last updated : July 07, 2024


Related Topics : Array, Simulation

Acceptance Rate : 39.69 %


Solutions

Python

# https://leetcode.com/problems/find-the-first-player-to-win-k-games-in-a-row/

from collections import deque

class Solution:
    def findWinningPlayer(self, skills: List[int], k: int) -> int:        
        gaming = deque(list(range(0,len(skills))))
        wins = {}

        currentKingOfHill = gaming.popleft()
        counter = 0
        while wins.get(currentKingOfHill, 0) < k :
            if counter > len(skills) :
                return currentKingOfHill
            if skills[currentKingOfHill] > skills[gaming[0]] :
                gaming.append(gaming.popleft())
                counter += 1
            else :
                counter = 0
                gaming.append(currentKingOfHill)
                currentKingOfHill = gaming.popleft()
            wins[currentKingOfHill] = wins.get(currentKingOfHill, 0) + 1
        return currentKingOfHill