Ctrl K

Min-Max Knockout

Easy
You are given an array players whose length is a power of two. Run a knockout tournament round by round. In every round neighbouring elements are paired up: (0, 1), (2, 3), (4, 5), … Pair number i (0-based) sends one number to the next round: the smaller of the two if i is even, the larger if i is odd. The winners form a new array, half as long, in the same order. Rounds continue until a single number is left. Return it.
Example 1
players=[6, 2, 9, 4, 1, 8, 7, 3] → 2

Round 1: min(6, 2) = 2, max(9, 4) = 9, min(1, 8) = 1, max(7, 3) = 7 → [2, 9, 1, 7]. Round 2: min(2, 9) = 2, max(1, 7) = 7 → [2, 7]. Final: min(2, 7) = 2.

Example 2
players=[5, 11] → 5

A single pair at position 0, so the smaller one, 5, wins.

Example 3
players=[42] → 42
Constraints
  • 1 ≤ len(players) ≤ 1024
  • len(players) is a power of two
  • 1 ≤ players[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsHow Long the Light Stayed On EasyRepack the Tray EasyQuiz Score Log EasyMirror and Negate a Bitmap EasySwap Rows and Columns Easy
loading Python…
Input
players=[6, 2, 9, 4, 1, 8, 7, 3]
Expected
2

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