Skip to content

Union Find problems,
and the tell.

You keep merging groups and asking whether two things are already in the same one. 51 problems in the catalogue carry this tag, from first-week easy to interview hard.

Free to start. Running and submitting a solution never costs credits.

How the pattern actually works.

One mechanism, and the mistake that costs people the problem.

The tell. You keep merging groups and asking whether two things are already in the same one.

The mechanism. Every item points at a parent; the root names the group. Union by size keeps the tree flat and path compression flattens it further, so both operations become effectively constant.

What goes wrong. Comparing parents instead of roots. Two items in one group can have different parents and the same root.

The ones asked most often.

By how often the catalogue records them being set, not by our opinion.

  1. Synonymous SentencesMediumasked at 3 companies
  2. Number of Connected Components in an Undirected GraphMediumasked at 3 companies
  3. Find the Safest Path in a GridMediumasked at 2 companies
  4. Satisfiability of Equality EquationsMediumasked at 2 companies
  5. Groups of StringsHardasked at 1 companies
  6. Reachable Nodes With RestrictionsMediumasked at 1 companies
  7. Subarray With Elements Greater Than Varying ThresholdHardasked at 1 companies
  8. Number of Operations to Make Network ConnectedMediumasked at 5 companies
  9. Detect Cycles in 2D GridMediumasked at 1 companies
  10. The Earliest Moment When Everyone Become FriendsMediumasked at 1 companies

Read it, watch it, then solve it.

The order that makes a pattern stick.

Everything in the app, in one place.

Practice, interviews and the tools, all free to start. Swipe to see the rest.

Free to start: 100 AI credits when you sign up and 100 every month. Start free in the app

About union find problems.

Free to start, no card.

Start practising
How do I know a problem is a union find problem?

You keep merging groups and asking whether two things are already in the same one.

How many union find problems should I solve?

Enough to stop needing the hint, which is usually ten to fifteen across the levels, not the whole list. The catalogue tags 51, split roughly 0 easy, 32 medium and 19 hard in the sample we show, so work up rather than across.

What goes wrong most often in union find problems?

Comparing parents instead of roots. Two items in one group can have different parents and the same root.

Is practising by pattern better than a problem sheet?

A sheet tells you what to solve. A pattern tells you why those problems sit together, which is the part that carries over to the problem you have not seen. That is why the app files every problem under its pattern.