Redundant connection directed
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.
0:00 of about 40 min
solution.py
InputExpectedGot
[[[1,2],[1,3],[2,3]]][2,3]not run yetsample