Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

edges =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

The redundant edge is the one that forms a cycle.

Approach

Union-Find (DSU):

  • For each edge (u,v), if u and v already have the same root, this edge is redundant. Return the last such edge.

Why it works

DSU tracks connected components. An edge within the same component closes a cycle.

Code
Loading...
Complexity
Time: O(E α(V))
Space: O(V)
Solution
Updated: 2026-02-23

Idea

The redundant edge is the one that forms a cycle.

Approach

Union-Find (DSU):

  • For each edge (u,v), if u and v already have the same root, this edge is redundant. Return the last such edge.

Why it works

DSU tracks connected components. An edge within the same component closes a cycle.

Code
Loading...
Complexity
Time: O(E α(V))
Space: O(V)