🚀 Phases 1–5 are live — Days 1–17 cover the foundations and the algorithmic patterns. See the roadmap →
Day 20 - Union FindPractice QuestionsOverview

Union Find Practice Questions

Eight interview classics. Every flavor of the DSU pattern is represented: plain connectivity, cycle detection, weighted offsets, grid encoding, equality constraints.

Before reading any solution, force yourself through the pattern-spotting checklist:

  1. Groups / equivalence classes?
  2. Only edge additions (no removals)?
  3. Connectivity, not paths?
  4. Pairs arriving as a stream?
  5. Cycle detection in disguise?

Five questions. The whole chapter, condensed.

Easy

ProblemPatternStatus
Number of ProvincesComponent counting on an adjacency matrixAvailable
Number of Connected Components in an Undirected GraphComponent counting from edge listAvailable

Medium

ProblemPatternStatus
Graph Valid TreeConnectivity + cycle detectionAvailable
Redundant ConnectionCycle detection on a stream of edgesAvailable
Satisfiability of Equality EquationsEquality constraints as unions, contradictions as cross-component checksAvailable
Smallest String With SwapsGroup indices into equivalence classes, sort within eachAvailable
Regions Cut By SlashesSubdivide each cell into 4 triangles and DSU themAvailable

Hard

ProblemPatternStatus
Evaluate DivisionWeighted DSU — multiplicative offsetsAvailable

More Practice (Coming Soon)

ProblemPatternStatus
Most Stones Removed With Same Row/ColImplicit DSU on rows ⊎ columnsComing Soon
Accounts MergeDSU over accounts indexed by shared emailComing Soon
Number of Islands IIDynamic island merging as cells turn onComing Soon
Bricks Falling When HitOffline reverse — turn deletions into insertionsComing Soon
Possible BipartitionDSU with parity / 2-coloringComing Soon
Number of Operations to Make Network ConnectedComponents vs spare edgesComing Soon
Lexicographically Smallest Equivalent StringDSU keeping the smallest rootComing Soon
Synonymous SentencesDSU on synonym pairs + DFSComing Soon