Skip to content
DeepForgeby svx
All problems
HardData Structuresds-183

Loser Tree Update

Problem

Simulate a loser tree built over a list of scores.

Each match compares two players: the winner advances and the loser is recorded. Ties go to the smaller index. Results are recorded round by round, left to right. Odd players receive a bye.

Return [winner_index, loser_indices_in_match_order].

Hint

A loser tree stores the loser of every match instead of replaying comparisons at query time.

Test cases

case 1
in: [[3,1,4,2]]
expected: [2,[1,3,0]]
case 2
in: [[5,5,1,1]]
expected: [0,[1,3,2]]
case 3
in: [[7]]
expected: [0,[]]
case 4
in: [[2,9,9,1]]
expected: [1,[0,3,2]]
Starter codePython
def loser_tree_lite(scores):
    # Your code here
    pass

4 test cases · run your code against them in the editor