Code RoomDirected Eulerian path reconstruction
HardPrep Room Coding #816

Directed Eulerian path reconstruction

CodingAlgorithms & data structuresSenior–Staff~45 min

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.

0:00 of about 45 min
InputExpectedGot
[3,[[0,1],[1,2]]][0,1,2]not run yetsample