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.
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.
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.
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.
Accepted:
Submission: