← All problems

Redundant Connection

Medium graphsunion-find LeetCode ↗
A tree plus one extra edge; return the edge that can be removed to restore the tree.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n α(n)), Space O(n)

Common pitfalls

  • Returning the first cycle edge instead of the last
  • DFS cycle detection is O(n^2)

Your solution

Log in to save your code and track progress.