LeetCode 684 Redundant Connection - Problem Statement

The problem

A tree with n nodes has exactly n - 1 edges. Given a graph with n nodes and n edges (one extra), find the edge that can be removed to make it a tree.

The extra edge creates exactly one cycle. Return that edge. If multiple answers exist, return the one appearing last in the input.

With edges = [[1,2],[1,3],[2,3]]:

  • Nodes 1, 2, 3 form a cycle: 1-2-3-1.
  • Removing any edge breaks the cycle.
  • [2,3] appears last in input. Return [2,3].

Constraints: 3n10003 \le n \le 1000. No duplicate edges.