Skip to content
Optimal Lab

Practice · 4 problems

Union-Find

0 of 4 solved on this device

Watch it first · interactiveUnion-find: connected groups →Read the explainer · optimal-roundWhen to use it, and its look-alikes ↗
  1. 143Number of Connected Components in an Undirected GraphGiven `n` nodes labelled 0..n-1 and a list of undirected edges, return the number of connected components in the graph.Medium
  2. 144Graph Valid TreeGiven `n` nodes labelled 0..n-1 and a list of undirected edges, determine whether they form a valid tree: fully connected and containing no cycles.Medium
  3. 145Redundant ConnectionA tree had one extra edge added, producing a graph with exactly one cycle. Given the edge list, return the edge that can be removed to restore a tree. If several qualify, return the one appearing LAST in the input.Medium
  4. 146Accounts MergeEach account is [name, email1, email2, ...]. Two accounts belong to the same person if they share any email; names may be shared by different people. Merge them and return each account as its name followed by its emails in sorted order.Medium