Ctrl K

King of the Hill

Medium
Players stand in a queue, each with a strength; all strengths in players are distinct. Every round, the first player in the queue (the king of the hill) fights the second. The stronger one stays at the front, and the loser goes to the back of the queue. The tournament ends as soon as someone wins streak rounds in a row. Return that player's strength.
Example 1
players=[4, 9, 2, 7, 1], streak=2 → 9

9 beats 4 (one win), then beats 2 (two in a row), and the tournament is over.

Example 2
players=[6, 3, 8, 5], streak=5 → 8

8 takes the hill in the second round and never loses after that, so it eventually wins 5 in a row.

Constraints
  • 2 ≤ len(players) ≤ 10⁵
  • 1 ≤ players[i] ≤ 10⁶
  • all values in players are distinct
  • 1 ≤ streak ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSpiral Readout MediumSpiral-Numbered Square MediumNext Step of a Cell Colony MediumZigzag Diagonal Sweep MediumMatch-Three Cascade Medium
loading Python…
Input
players=[4, 9, 2, 7, 1], streak=2
Expected
9

Run checks the first 3 tests in your browser. Submit checks all 105 tests on the server, hidden ones included.