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

Question

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.

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.