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

Question

Given a directed multigraph on n nodes (0..n-1) with a list of directed edges, reconstruct the lexicographically smallest Eulerian circuit: a closed walk starting and ending at the same node that uses every edge exactly once. Return it as the list of visited nodes (length = number_of_edges + 1). If no Eulerian circuit exists (degree imbalance or the edges are not all connected into one circuit), return an empty list. Start the circuit from the smallest-numbered node that has an outgoing edge. Constraints: 1 <= n <= 1000; edges may include self-loops and parallel edges.

Implement
lex_eulerian_circuit(n: int, edges: list[list[int]]) → list[int]
Examples
in[3,[[0,1],[1,2],[2,0]]]out[0,1,2,0]
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.