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

Question

Given a directed multigraph with n nodes (0..n-1) and a list of directed edges (parallel edges allowed), reconstruct an Eulerian circuit: a closed walk that uses every edge exactly once and returns to its start. Return the sequence of visited nodes (length = #edges + 1); if no Eulerian circuit exists return an empty list. To make the output deterministic, when leaving a node always take the unused outgoing edge to the smallest-numbered neighbor first. For an empty edge list return []. Assume 1 <= n <= 2000.

Implement
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.