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.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.
players=[5, 11] → 5
A single pair at position 0, so the smaller one, 5, wins.
players=[42] → 42
players=[6, 2, 9, 4, 1, 8, 7, 3]
2
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.