Code Room
CodingHardcod-g914
Subject Union findLevel Senior–Staff~40 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A rooted tree with n nodes (labeled 1..n) had exactly one extra directed edge added. The result is a directed graph where each edge u->v means v's parent is u. Because of the added edge, the graph violates a tree in one of two ways: some node has two parents, or there is a directed cycle (or both). Given the edges in the order they were added, return the one edge that can be removed so the remaining graph is a rooted tree. If multiple answers, return the edge that occurs last in the input.

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