Code RoomLexicographically smallest Eulerian path
HardPrep Room Coding #1448

Lexicographically smallest Eulerian path

CodingAlgorithms & data structuresSenior–Staff~40 min

Given a directed multigraph on nodes 0..n-1 as a list of edges [u, v], reconstruct the lexicographically smallest Eulerian path: a sequence of node ids that uses every edge exactly once, where among all valid Eulerian paths you return the one whose node sequence is smallest in dictionary order. Return the sequence as a list of node ids (length = number of edges + 1). If no Eulerian path exists, return an empty list. Constraints: up to 60 edges; the graph may have parallel edges.

Implement
euler_path(n: int, edges: list[list[int]]) → list[int]
Examples
in[3,[[0,1],[1,2],[2,0],[0,2]]]out[0,1,2,0,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
InputExpectedGot
[3,[[0,1],[1,2],[2,0],[0,2]]][0,1,2,0,2]not run yetsample