All problems
Tournament Tree Winner
Problem
Find the overall winner of a knockout tournament.
results holds the score of each player, indexed from 0. Players are paired in index order; the higher score advances and a tie goes to the smaller index. Odd players receive a bye. Continue in rounds until one player remains.
Return the winner's original index, or None for an empty list.
Hint
Simulate round by round, letting the last player advance when the round size is odd.
Test cases
case 1
in: [[3,1,4,2]]
expected: 2
case 2
in: [[5,5,1,1]]
expected: 0
case 3
in: [[7]]
expected: 0
case 4
in: [[]]
expected: null
case 5
in: [[2,9,9,1]]
expected: 1
Starter codePython
def tournament_winner(results):
# Your code here
pass5 test cases · run your code against them in the editor