Pattern · Union Find

Union Find interview questions

52 union find problems tagged across recent interview reports. Drilled most heavily by doordash, tiktok, and snap.

Founder's read

Union Find is a data structure that tracks connected components in a graph and answers reachability queries in near-constant time. With 52 problems tagged across the pattern, it's a high-frequency ask at DoorDash (24 problems), TikTok (21), and Snap (20). Candidates often recognize it too late: the problem statement hides the connection, you're merging sets, validating paths, or counting islands. If a Union Find variant lands in your live assessment and you freeze, StealthCoder reads the problem and delivers the solution invisible to the proctor.

Most-asked union find problems

#ProblemDiff# Companies
01Number of IslandsMEDIUM86
02Longest Consecutive SequenceMEDIUM36
03Evaluate DivisionMEDIUM17
04Max Area of IslandMEDIUM14
05Making A Large IslandHARD11
06Accounts MergeMEDIUM8
07Number of Distinct IslandsMEDIUM8
08Number of ProvincesMEDIUM6
09Possible BipartitionMEDIUM6
10Surrounded RegionsMEDIUM6
11Graph Valid TreeMEDIUM5
12Min Cost to Connect All PointsMEDIUM5
13Number of Islands IIHARD5
14Number of Operations to Make Network ConnectedMEDIUM5
15Swim in Rising WaterHARD5
16Count Sub IslandsMEDIUM3
17Find the Safest Path in a GridMEDIUM3
18Make Lexicographically Smallest Array by Swapping ElementsMEDIUM3
19Minimize Malware SpreadHARD3
20Minimum Number of Visited Cells in a GridHARD3
21Most Stones Removed with Same Row or ColumnMEDIUM3
22Number of Connected Components in an Undirected GraphMEDIUM3
23Bricks Falling When HitHARD2
24Is Graph Bipartite?MEDIUM2
25Path With Maximum Minimum ValueMEDIUM2
26Path With Minimum EffortMEDIUM2
27Redundant ConnectionMEDIUM2
28Satisfiability of Equality EquationsMEDIUM2
29Smallest String With SwapsMEDIUM2
30Check if There is a Valid Path in a GridMEDIUM1
31Count Unreachable Pairs of Nodes in an Undirected GraphMEDIUM1
32Couples Holding HandsHARD1
33Detect Cycles in 2D GridMEDIUM1
34Distance to a Cycle in Undirected GraphHARD1
35Divide Nodes Into the Maximum Number of GroupsHARD1
36Groups of StringsHARD1
37Last Day Where You Can Still CrossHARD1
38Lexicographically Smallest Equivalent StringMEDIUM1
39Maximum Number of Points From Grid QueriesHARD1
40Maximum Segment Sum After RemovalsHARD1
41Minimize Malware Spread IIHARD1
42Minimum Cost Walk in Weighted GraphHARD1
43Minimum Runes to Add to Cast SpellHARD1
44Number of Closed IslandsMEDIUM1
45Number of Ways to Reorder Array to Get Same BSTHARD1
46Rank Transform of a MatrixHARD1
47Reachable Nodes With RestrictionsMEDIUM1
48Similar String GroupsHARD1
49Subarray With Elements Greater Than Varying ThresholdHARD1
50Sum of Remoteness of All CellsMEDIUM1

Showing top 50 of 52 union find problems by # companies asking.

The hedge for the live OA

You can't drill every union find variant before the assessment. StealthCoder runs invisibly during screen share and solves whichever variant they throw at you. No browser extension. No detection signature. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

Union Find problems fall into three buckets: explicit graph connectivity (validate trees, count components), implicit grid connectivity (islands, bricks falling), and dynamic equivalence (accounts merging, evaluate division). The pattern's signature is a sequence of union and find operations where you need to answer "are two nodes connected?" or "how many disjoint sets exist?" Drilling accounts-merge, couples-holding-hands, and detect-cycles-in-2d-grid first builds your intuition for rank-and-path-compression optimizations. Harder variants like divide-nodes-into-the-maximum-number-of-groups layer bipartite graph logic on top. Most candidates underestimate the variant space. StealthCoder is your safety net when a problem variant you didn't practice lands live.

Companies that hire most on union find

The honest play

52 union find problems. You won't drill them all. Pass anyway.

Union Find is one of the patterns interviews actually filter on. Memorizing every variant in a week is a fantasy. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds, no matter which union find flavor lands in your live OA. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Union Find interview FAQ

How many Union Find problems should I drill before my assessment?+

Start with 8-12 problems across the three buckets: graph connectivity, grid problems, and dynamic equivalence. accounts-merge and couples-holding-hands are canonical. Then solve 2-3 hard variants. 52 problems exist; you won't hit all of them live, but pattern recognition compounds fast.

How do I recognize a Union Find problem in the wild?+

Look for "connected," "component," "merge," "equivalence," or "relationship" in the problem statement. If you're tracking which nodes belong to the same group and answering connectivity queries, it's likely Union Find. Grid island problems often hint at it implicitly.

Is Union Find the most important pattern for DoorDash and TikTok?+

It's top-tier. DoorDash has 24 Union Find problems in their assessment pool; TikTok has 21. But they also test trees, graphs, and dynamic programming heavily. Union Find is a high-value pattern to lock down, not the only one.

What's the hardest Union Find variant I should know?+

divide-nodes-into-the-maximum-number-of-groups requires Union Find plus bipartite graph coloring. distance-to-a-cycle-in-undirected-graph and graph-valid-tree also fuse Union Find with other graph concepts. Practice these last.

Do I need perfect rank compression and path compression to pass?+

Path compression alone (make every node point directly to root) passes most problems. Full rank-by-union optimization matters for very large datasets or strict time limits. Implement it clean, test it, move on.

Problem and frequency data sourced from public community-maintained interview-report repos. Problems and trademarks © LeetCode.