Skip to main content

Redundant Connection

MediumPremium

You are given a tree with n nodes labeled from 1 to n, with one additional edge added to it. This extra edge creates a cycle in the graph.

Your task is to find the edge that, if removed, will make the graph a tree again.

Return the edge that can be removed to eliminate the cycle. If there are multiple answers, return the one that appears last in the input list.

Example

Input: edges = [[1,2], [1,3], [2,3]] 1 / \ 2---3 Output: [2,3]