Eulerian circuit reconstruction
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.
0:00 of about 30 min
solution.py
InputExpectedGot
[3,[[0,1],[1,2],[2,0]]][0,1,2,0]not run yetsample