Code RoomRedundant edge in tree
MediumPrep Room Coding #74

Redundant edge in tree

CodingAlgorithms & data structuresMid–Senior~25 min

A connected undirected graph that started as a tree on n nodes (labeled 1..n) had exactly one extra edge added, creating exactly one cycle. You are given the n edges as [u, v] in the order they were added. Return the one edge that can be removed so the result is a tree; if multiple answers, return the edge that appears last in the input. Nodes are 1-indexed.

Implement
redundant_edge(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 25 min
InputExpectedGot
[[[1,2],[1,3],[2,3]]][2,3]not run yetsample