union find
union find is one of the most repeated interview dimensions. Start with edge-safe fundamentals, then move into pattern-level trade-offs.
Interview Signal
Frequently tests problem modeling, edge handling, and verbal clarity.
Common Pitfall
Template-only answers break under follow-up questioning.
Practice Strategy
Practice in 3-5 problem rounds and always review complexity alternatives.
Recommended Progression
Foundation
High-Pressure Round
Longest Consecutive Sequence
Find the length of the longest consecutive elements sequence in an unsorted array using array scanning and hash lookup.
Surrounded Regions
Transform the matrix in-place by marking regions surrounded by 'X' as 'X', while keeping border-adjacent 'O's intact.
Number of Islands
Count the number of distinct islands in a binary grid using array traversal combined with depth-first search exploration…
Evaluate Division
Compute the results of division queries from given equations using graph traversal and depth-first search efficiently.
Number of Provinces
Solve Number of Provinces by scanning the adjacency matrix and launching DFS once per unvisited city component.
Redundant Connection
Identify and remove the redundant edge that causes a cycle in a graph starting as a tree.
Redundant Connection II
Find and remove the redundant connection in a directed graph that was originally a rooted tree.
Max Area of Island
Find the largest connected land area in a binary grid using array traversal and depth-first search efficiently.
Accounts Merge
Merge accounts by connecting emails and returning each user's sorted email list using array scanning and hash lookup eff…
Couples Holding Hands
This problem requires arranging couples sitting apart in a row with the minimum number of swaps using graph traversal an…
Swim in Rising Water
Solve the problem of swimming through a grid of rising water with a binary search on the valid answer space.
Is Graph Bipartite?
Determine whether an undirected graph can be split into two independent sets using DFS, BFS, or Union Find patterns.
Bricks Falling When Hit
Bricks Falling When Hit challenges your ability to simulate brick falls after sequential erasures using Union Find.
Making A Large Island
Calculate the largest island size by converting at most one zero in a binary grid using array and DFS techniques efficie…
Similar String Groups
Determine the number of connected groups of similar strings by swapping at most two letters using array scanning and has…
Possible Bipartition
Determine if a group of n people with mutual dislikes can be split into two non-conflicting groups using graph traversal…
Minimize Malware Spread
Identify which single infected node to remove to minimize total malware spread in a connected network graph efficiently.
Minimize Malware Spread II
Minimize Malware Spread II asks to minimize the spread of malware in a network of nodes by removing one infected node.
Most Stones Removed with Same Row or Column
Maximize the number of stones removed from a 2D plane using graph traversal and DFS.
Largest Component Size by Common Factor
Find the largest connected component in an array where edges exist between numbers sharing a common factor greater than …
Regions Cut By Slashes
Determine the number of regions in a grid divided by slashes using array scanning and union-find techniques efficiently.
Satisfiability of Equality Equations
Determine if it's possible to assign values to variables such that all equations are satisfied based on equality and ine…
Number of Enclaves
This problem involves finding the number of land cells that cannot reach the boundary in a grid using DFS and array mani…
Lexicographically Smallest Equivalent String
Determine the lexicographically smallest string by modeling character equivalences with union find efficiently.
Smallest String With Swaps
Find the lexicographically smallest string by swapping characters in given pairs of indices.
Number of Closed Islands
Count the number of closed islands in a 2D grid using array traversal and depth-first search efficiently.
Count Servers that Communicate
Count Servers that Communicate involves identifying servers in a grid that can communicate based on row or column connec…
Number of Operations to Make Network Connected
Determine the minimum number of operations required to connect all computers in a network with a limited number of cable…
Validate Binary Tree Nodes
Validate Binary Tree Nodes problem requires checking if a set of nodes forms a valid binary tree using graph traversal.
Check if There is a Valid Path in a Grid
Check if there is a valid path from the upper-left to the bottom-right corner of a grid using depth-first search.
Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree
Identify critical and pseudo-critical edges in a weighted graph's minimum spanning tree using Union Find efficiently.
Detect Cycles in 2D Grid
Detect cycles in a 2D character grid using DFS while carefully tracking parent cells to avoid invalid revisits.
Number of Ways to Reorder Array to Get Same BST
Determine the number of ways to reorder an array to get the same binary search tree (BST) from its insertion order.
Remove Max Number of Edges to Keep Graph Fully Traversable
Maximize the number of edges that can be removed while keeping the graph fully traversable for both Alice and Bob.
Min Cost to Connect All Points
Min Cost to Connect All Points asks for the minimum cost to connect all points on a 2D plane, using manhattan distances …
Graph Connectivity With Threshold
In 'Graph Connectivity With Threshold,' determine if cities are connected based on common divisors exceeding a threshold…
Path With Minimum Effort
Find the minimum effort required to travel from the top-left to the bottom-right of a grid, considering height differenc…
Rank Transform of a Matrix
Compute a unique rank matrix using graph indegree with topological ordering, ensuring each element reflects its relative…
Checking Existence of Edge Length Limited Paths
Solve the problem of checking if there exists a path between two nodes under edge length constraints using efficient tec…
Minimize Hamming Distance After Swap Operations
Solve Minimize Hamming Distance After Swap Operations by grouping swappable indices and matching value counts inside eac…
Count Sub Islands
Identify and count all islands in grid2 that are fully contained within islands of grid1 using DFS traversal efficiently…
Last Day Where You Can Still Cross
Find the last day to walk from top to bottom in a flooded matrix by using binary search and graph traversal techniques.
Find if Path Exists in Graph
Determine if a valid path exists between two vertices in a bi-directional graph using traversal techniques.
GCD Sort of an Array
The GCD Sort problem challenges you to sort an array using a specific gcd-based swap method.
Smallest Missing Genetic Value in Each Subtree
Determine the smallest missing genetic value in each subtree using binary-tree traversal and precise state tracking effi…
Process Restricted Friend Requests
Determine which friend requests can be accepted without violating direct or indirect restrictions using union-find logic…
Find All People With Secret
Find all people who receive a secret through meetings using graph traversal with depth-first search efficiently and corr…
Groups of Strings
Group words into connected sets using operations on characters with string and bit manipulation techniques.
Count Unreachable Pairs of Nodes in an Undirected Graph
Calculate the total number of node pairs in an undirected graph that cannot reach each other using DFS, BFS, or Union Fi…
Subarray With Elements Greater Than Varying Threshold
Find the size of a subarray with all elements greater than threshold divided by length using stack-based state managemen…
Reachable Nodes With Restrictions
In the 'Reachable Nodes With Restrictions' problem, find the maximum reachable nodes from node 0 in a tree while avoidin…
Maximum Segment Sum After Removals
Calculate the maximum segment sum after sequential removals using array plus union find for efficient merging of segment…
Number of Good Paths
Count all good paths in a tree by scanning node values and using hash maps to track valid connections efficiently.
Longest Uploaded Prefix
Calculate the longest continuous uploaded prefix in a video stream efficiently using a mix of binary search and data str…
Minimum Score of a Path Between Two Cities
Find the minimum distance in a path connecting two cities using graph traversal strategies efficiently.
Divide Nodes Into the Maximum Number of Groups
Determine the maximum number of groups nodes can form in a graph using depth-first traversal without violating edge conn…
Maximum Number of Points From Grid Queries
Solve the Maximum Number of Points From Grid Queries problem using two-pointer scanning and invariant tracking.
Find the String with LCP
Determine the lexicographically smallest string matching a given LCP matrix using state transition dynamic programming.
Minimum Number of Visited Cells in a Grid
Determine the minimum number of cells to visit in a grid using state transition dynamic programming and efficient traver…
Maximum Number of Fish in a Grid
Maximize the number of fish that can be caught by performing DFS on an optimal starting point in a grid.
Count the Number of Complete Components
Determine the number of complete connected components in an undirected graph using efficient traversal techniques and gr…
Greatest Common Divisor Traversal
Determine if every index in an array can be reached from any other using traversals based on greatest common divisors.
Find the Safest Path in a Grid
Find the Safest Path in a Grid uses binary search and BFS to maximize path safeness from thieves in a grid.
Make Lexicographically Smallest Array by Swapping Elements
Solve the problem of making an array lexicographically smallest through element swaps under a limit constraint.
Minimum Cost Walk in Weighted Graph
Find the minimum cost walk in a weighted graph using array and bit manipulation techniques for efficient path calculatio…
Check if the Rectangle Corner Is Reachable
Determine if there is a valid path from the bottom-left to top-right of a rectangle while avoiding circles.
Count Connected Components in LCM Graph
Determine the number of connected components in an LCM-based graph using array scanning and hash-based connectivity chec…
Properties Graph
Find the number of connected components in an undirected graph formed by properties arrays, using array scanning and has…
Path Existence Queries in a Graph I
Determine if paths exist between nodes using array scanning and hash lookups for efficient component checks in graphs.
Maximize Spanning Tree Stability with Upgrades
Maximizing the stability of a spanning tree with upgrades requires careful optimization of edge strengths using binary s…
Power Grid Maintenance
Determine which power stations remain connected after maintenance using array scanning and hash lookups to track compone…
Minimum Time for K Connected Components
Find the minimum time to remove edges such that a graph with n nodes has at least k connected components.
Minimize Maximum Component Cost
Minimize Maximum Component Cost leverages binary search over edge weights to optimize the cost of graph components after…
Count Islands With Total Value Divisible by K
Count the number of islands in a grid where the sum of each island's values is divisible by a given integer k.