Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find The First Player to win K Games in a Row

XPChallenge Points: 25
levelLevel: Medium

You have n players with unique skills skills[i] standing in a queue 0..n-1. Repeatedly, the first two play; the higher skill wins and stays in front, the loser goes to the back. The winner is the first to achieve k consecutive wins. Return that player’s initial index.

Key idea (O(n + k)): Track only the current champion and their streak while scanning opponents left→right once. If no one hits k during this pass, the champion is the max skill player and will eventually reach k.

Example 1:

Input: skills = [1, 3, 2, 5, 4], k = 1

Output: 1

Explanation:

First match (0 vs 1): 1 < 3 → player 1 wins once → already k=1. Answer 1.

Example 2:

Input: skills = [3, 1, 2, 7, 4], k = 10

Output: 3

Explanation:

Player with max skill is index 3 (skill 7). Even if k is large, once index 3 becomes champ, no one can beat them; they’ll accumulate wins until reaching k. So answer 3.

Example 3:

Input: skills = [5, 6, 1, 4, 3, 2], k = 2

Output: 1

Explanation:

(0 vs 1): 5 < 6 → champ 1, streak=1 (1 vs 2): 6 > 1 → champ 1, streak=2 Answer 1.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result