Redundant Connection
CodingPhoneSoftware EngineerReported Apr, 2026
Examples
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]
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]
In this problem, a tree is an undirected graph that is connected and has no cycles.
You are given a graph that started as a tree with n nodes labeled from 1 to n, then one additional edge was added. The added edge connects two different vertices that were not already connected by an edge.
Given edges, return an edge that can be removed so the resulting graph is a tree. If there are multiple answers, return the answer that occurs last in the input.
n == edges.length3 <= n <= 1000edges[i].length == 21 <= ai < bi <= edges.length