Redundant Link
A tree with nodes 1..n had one extra edge added. Return the edge that can be removed to make it a tree again; if several work, return the one that appears last in edges.
Requirements
- Union–find with path compression.
Examples
EXAMPLE WALKTHROUGHtriangle
A guided view of the published example, not a trace of your code.
INPUT
[[[1,2],[1,3],[2,3]]]TASKredundant_link()
EXPECTED OUTPUT
[2,3]Start with the input values shown in this example.
Example 1 of 3
Input: edges = [[1,2],[1,3],[2,3]]
Output: [2,3]
Explanation: triangle
Input: edges = [[1,2],[2,3],[3,4],[1,4],[1,5]]
Output: [1,4]
Explanation: square
Input: edges = [[1,2],[2,3],[1,3],[3,4]]
Output: [1,3]
Explanation: extra edge earlier
Hint 1
Process edges in order; the first edge joining two already-connected nodes is the answer.