Union-Find (Disjoint Set)
Union-Find (a disjoint-set structure) tracks which elements belong to the same group and merges groups in near-constant time. Use it for dynamic connectivity — counting components, detecting a cycle in an undirected graph, or grouping by equivalence.
6 LeetCode problems solved with the Union-Find (Disjoint Set) pattern. Practice them with spaced repetition so the pattern sticks.
- Accounts MergeMEDIUM · O(N*K*α(N) + N*K*log(N*K))
- Find Critical and Pseudo-Critical Edges in Minimum Spanning TreeHARD · O(E^2 * alpha(V))
- Graph Valid TreeMEDIUM · O(n + e)
- Greatest Common Divisor TraversalHARD · O(n + M log log M)
- Number of Connected Components in an Undirected GraphMEDIUM · O(E * alpha(N))
- Redundant ConnectionMEDIUM · O(n α(n))
See the full solution
The complete approach, reference solutions in 5 languages, and a step-by-step visualization — then add this problem to your spaced-repetition schedule.
Start free →