Redundant connection
Mediumgraphunion find
A tree with n nodes labelled 1 to n got one extra edge, creating a cycle. edges lists the edges in order. Return an edge whose removal leaves a tree; if several qualify, return the last one in edges.
Example 1
Input: edges = [[1,2],[1,3],[2,3]] Output: [2,3]
Example 2
Input: edges = [[1,2],[2,3],[3,4],[1,4],[1,5]] Output: [1,4]
Constraints
- 3 ≤ n == edges.length ≤ 1000
- The graph is a tree plus one edge
Submit checks your solution against 7 tests, including hidden ones.
/**
* @param {int[][]} edges
* @return {int[]}
*/
function findRedundantConnection(edges) {
}