Code Room
CodingHardcod-g895
Subject Eulerian pathLevel Senior–Staff~40 minCommon in Algorithms & data structures interviewsIndustries Computer games, Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.