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

Question

Given a directed graph with n nodes (0..n-1) and directed edges [u, v], reconstruct an Eulerian path: a walk using every directed edge exactly once. If one exists, return the list of node labels visited in order (length = number_of_edges + 1); the path must begin at the unique vertex with out-degree minus in-degree equal to 1 when such a vertex exists, otherwise at the lowest-numbered vertex that has an outgoing edge. Within each vertex, leave via edges in the input order. If no Eulerian path exists, return []. Constraints: 1 <= n <= 1000.

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