Lexicographically smallest tournament ranking
A tournament is a directed graph on n players (0..n-1) where, for every unordered pair {i, j}, exactly one directed edge exists; matches is the list of those edges, where [u, v] means u beat v. A full ranking is an ordering of all players where each player beat the next one in the ordering (a Hamiltonian path along the beat edges) -- one always exists in a tournament. Return the lexicographically smallest such ordering as a list of player ids. Constraints: 2 <= n <= 20.
Implement
lex_ranking(n: int, matches: list[list[int]]) → list[int]Examples
in
[3,[[0,1],[1,2],[2,0]]]out[0,1,2]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 40 min
solution.py
InputExpectedGot
[3,[[0,1],[1,2],[2,0]]][0,1,2]not run yetsample