Union Find Problems
Master union find problems with AI-powered solutions. Get instant coding assistance during your technical interviews for all 55 problems in this category.
Total Problems: 55
Easy: 1
Medium: 31
Hard: 23
Showing 50 of 55 problems
Problems
Scroll within this area to browse all problems
#
Title
Difficulty
Union Find LeetCode Problems List
- 200. Number of Islands - Medium - Union FindGiven an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by wa... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 128. Longest Consecutive Sequence - Medium - Union FindGiven an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n... Topics: Array, Hash Table, Union Find
- 721. Accounts Merge - Medium - Union FindGiven a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the el... Topics: Array, Hash Table, String, Depth-First Search, Breadth-First Search, Union Find, Sorting
- 801. Is Graph Bipartite? - Medium - Union FindThere is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 854. Making A Large Island - Hard - Union FindYou are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applyi... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 794. Swim in Rising Water - Hard - Union FindYou are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j). It starts raining, and water gra... Topics: Array, Binary Search, Depth-First Search, Breadth-First Search, Union Find, Heap (Priority Queue), Matrix
- 399. Evaluate Division - Medium - Union FindYou are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equa... Topics: Array, String, Depth-First Search, Breadth-First Search, Union Find, Graph, Shortest Path
- 3863. Power Grid Maintenance - Medium - Union FindYou are given an integer c representing c power stations, each with a unique identifier id from 1 to c (1‑based indexing). These stations are intercon... Topics: Array, Hash Table, Depth-First Search, Breadth-First Search, Union Find, Graph, Heap (Priority Queue), Ordered Set
- 2035. Count Sub Islands - Medium - Union FindYou are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is a group of ... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 684. Redundant Connection - Medium - Union FindIn this problem, a tree is an undirected graph that is connected and has no cycles. You are given a graph that started as a tree with n nodes labeled ... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 1380. Number of Closed Islands - Medium - Union FindGiven a 2D grid consists of 0s (land) and 1s (water). An island is a maximal 4-directionally connected group of 0s and a closed island is an island t... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 3823. Count Islands With Total Value Divisible by K - Medium - Union FindYou are given an m x n matrix grid and a positive integer k. An island is a group of positive integers (representing land) that are 4-directionally co... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 695. Max Area of Island - Medium - Union FindYou are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 2121. Find if Path Exists in Graph - Easy - Union FindThere is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 770. Couples Holding Hands - Hard - Union FindThere are n couples sitting in 2n seats arranged in a row and want to hold hands. The people and seats are represented by an integer array row where r... Topics: Greedy, Depth-First Search, Breadth-First Search, Union Find, Graph
- 547. Number of Provinces - Medium - Union FindThere are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 130. Surrounded Regions - Medium - Union FindYou are given an m x n matrix board containing letters 'X' and 'O', capture regions that are surrounded: Connect: A cell is connected to adjacent cell... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 1663. Detect Cycles in 2D Grid - Medium - Union FindGiven a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid. A cycle is a path ... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 2793. Count the Number of Complete Components - Medium - Union FindYou are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 1058. Lexicographically Smallest Equivalent String - Medium - Union FindYou are given two strings of the same length s1 and s2 and a string baseStr. We say s1[i] and s2[i] are equivalent characters. For example, if s1 = "a... Topics: String, Union Find
- 1753. Path With Minimum Effort - Medium - Union FindYou are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the heigh... Topics: Array, Binary Search, Depth-First Search, Breadth-First Search, Union Find, Heap (Priority Queue), Matrix
- 1275. Validate Binary Tree Nodes - Medium - Union FindYou have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the... Topics: Tree, Depth-First Search, Breadth-First Search, Union Find, Graph, Binary Tree
- 1706. Min Cost to Connect All Points - Medium - Union FindYou are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi]. The cost of connecting two po... Topics: Array, Union Find, Graph, Minimum Spanning Tree
- 1032. Satisfiability of Equality Equations - Medium - Union FindYou are given an array of strings equations that represent relationships between variables where each string equations[i] is of length 4 and takes one... Topics: Array, String, Union Find, Graph
- 685. Redundant Connection II - Hard - Union FindIn this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this n... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 964. Minimize Malware Spread II - Hard - Union FindYou are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i... Topics: Array, Hash Table, Depth-First Search, Breadth-First Search, Union Find, Graph
- 1442. Number of Operations to Make Network Connected - Medium - Union FindThere are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 1613. Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree - Hard - Union FindGiven a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [ai, bi, weighti] represents... Topics: Union Find, Graph, Sorting, Minimum Spanning Tree, Strongly Connected Component
- 2588. Maximum Number of Points From Grid Queries - Hard - Union FindYou are given an m x n integer matrix grid and an array queries of size k. Find an array answer of size k such that for each integer queries[i] you st... Topics: Array, Two Pointers, Breadth-First Search, Union Find, Sorting, Heap (Priority Queue), Matrix
- 984. Most Stones Removed with Same Row or Column - Medium - Union FindOn a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone. A stone can be removed if it sha... Topics: Hash Table, Depth-First Search, Union Find, Graph
- 922. Possible Bipartition - Medium - Union FindWe want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 1257. Rank Transform of a Matrix - Hard - Union FindGiven an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col]. The rank is an integer that represents how l... Topics: Array, Union Find, Graph, Topological Sort, Sorting, Matrix
- 3908. Minimum Time for K Connected Components - Medium - Union FindYou are given an integer n and an undirected graph with n nodes labeled from 0 to n - 1. This is represented by a 2D array edges, where edges[i] = [ui... Topics: Binary Search, Union Find, Graph, Sorting
- 2582. Minimum Score of a Path Between Two Cities - Medium - Union FindYou are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 1223. Graph Connectivity With Threshold - Hard - Union FindWe have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y s... Topics: Array, Math, Union Find, Number Theory
- 869. Similar String Groups - Hard - Union FindTwo strings, X and Y, are considered similar if either they are identical or we can make them equivalent by swapping at most two letters (in distinct ... Topics: Array, Hash Table, String, Depth-First Search, Breadth-First Search, Union Find
- 2403. Count Unreachable Pairs of Nodes in an Undirected Graph - Medium - Union FindYou are given an integer n. There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i]... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 2914. Find the Safest Path in a Grid - Medium - Union FindYou are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents: A cell containing a thief if grid[r][c] = 1 An empty cell if grid[r][... Topics: Array, Binary Search, Breadth-First Search, Union Find, Heap (Priority Queue), Matrix
- 960. Minimize Malware Spread - Hard - Union FindYou are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i... Topics: Array, Hash Table, Depth-First Search, Breadth-First Search, Union Find, Graph
- 3809. Properties Graph - Medium - Union FindYou are given a 2D integer array properties having dimensions n x m and an integer k. Define a function intersect(a, b) that returns the number of dis... Topics: Array, Hash Table, Depth-First Search, Breadth-First Search, Union Find, Graph
- 2419. Subarray With Elements Greater Than Varying Threshold - Hard - Union FindYou are given an integer array nums and an integer threshold. Find any subarray of nums of length k such that every element in the subarray is greater... Topics: Array, Stack, Union Find, Monotonic Stack
- 821. Bricks Falling When Hit - Hard - Union FindYou are given an m x n binary grid, where each 1 represents a brick and 0 represents an empty space. A brick is stable if: It is directly connected to... Topics: Array, Union Find, Matrix
- 2708. Find the String with LCP - Hard - Union FindWe define the lcp matrix of any 0-indexed string word of n lowercase English letters as an n x n grid such that: lcp[i][j] is equal to the length of t... Topics: Array, String, Dynamic Programming, Greedy, Union Find, Matrix
- 2131. Smallest Missing Genetic Value in Each Subtree - Hard - Union FindThere is a family tree rooted at 0 consisting of n nodes numbered 0 to n - 1. You are given a 0-indexed integer array parents, where parents[i] is the... Topics: Dynamic Programming, Tree, Depth-First Search, Union Find
- 3881. Minimize Maximum Component Cost - Medium - Union FindYou are given an undirected connected graph with n nodes labeled from 0 to n - 1 and a 2D integer array edges where edges[i] = [ui, vi, wi] denotes an... Topics: Binary Search, Union Find, Graph, Sorting
- 3219. Make Lexicographically Smallest Array by Swapping Elements - Medium - Union FindYou are given a 0-indexed array of positive integers nums and a positive integer limit. In one operation, you can choose any two indices i and j and s... Topics: Array, Union Find, Sorting
- 1692. Number of Ways to Reorder Array to Get Same BST - Hard - Union FindGiven an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the eleme... Topics: Array, Math, Divide and Conquer, Dynamic Programming, Tree, Union Find, Binary Search Tree, Memoization, Combinatorics, Binary Tree
- 2827. Greatest Common Divisor Traversal - Hard - Union FindYou are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != ... Topics: Array, Math, Union Find, Number Theory
- 2505. Number of Good Paths - Hard - Union FindThere is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. You are gi... Topics: Array, Hash Table, Tree, Union Find, Graph, Sorting
- 3902. Maximize Spanning Tree Stability with Upgrades - Hard - Union FindYou are given an integer n, representing n nodes numbered from 0 to n - 1 and a list of edges, where edges[i] = [ui, vi, si, musti]: ui and vi indicat... Topics: Binary Search, Greedy, Union Find, Graph, Minimum Spanning Tree
- 3348. Minimum Cost Walk in Weighted Graph - Hard - Union FindThere is an undirected weighted graph with n vertices labeled from 0 to n - 1. You are given the integer n and an array edges, where edges[i] = [ui, v... Topics: Array, Bit Manipulation, Union Find, Graph
- 1701. Remove Max Number of Edges to Keep Graph Fully Traversable - Hard - Union FindAlice and Bob have an undirected graph of n nodes and three types of edges: Type 1: Can be traversed by Alice only. Type 2: Can be traversed by Bob on... Topics: Union Find, Graph
- 1073. Number of Enclaves - Medium - Union FindYou are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell. A move consists of walking from one land cell t... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 2583. Divide Nodes Into the Maximum Number of Groups - Hard - Union FindYou are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n. You are also given a 2D... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 1815. Checking Existence of Edge Length Limited Paths - Hard - Union FindAn undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. ... Topics: Array, Two Pointers, Union Find, Graph, Sorting
Related LeetCode Topics
- Array LeetCode Problems
- Backtracking LeetCode Problems
- Biconnected Component LeetCode Problems
- Binary Indexed Tree LeetCode Problems
- Binary Search LeetCode Problems
- Binary Search Tree LeetCode Problems
- Binary Tree LeetCode Problems
- Bit Manipulation LeetCode Problems
- Bitmask LeetCode Problems
- Brainteaser LeetCode Problems
- Breadth-First Search LeetCode Problems
- Bucket Sort LeetCode Problems
- Combinatorics LeetCode Problems
- Concurrency LeetCode Problems
- Counting LeetCode Problems
- Counting Sort LeetCode Problems
- Data Stream LeetCode Problems
- Database LeetCode Problems
- Depth-First Search LeetCode Problems
- Design LeetCode Problems