Pattern
Union Find
A compact view of archive entries grouped by recurring technique.
31 entries
31 entries tagged as Union Find.
21.04.2026
medium1722. Minimize Hamming Distance After Swap Operations
Diff src vs target after rearrange by rules
31.12.2025
hard1970. Last Day Where You Can Still Cross
Last day top connected to bottom in 2D matrix
19.12.2025
hard2092. Find All People With Secret
Time based secret spread in a graph
06.11.2025
medium3607. Power Grid Maintenance
Smallest in subgraph after turning some nodes off
24.07.2025
hard2322. Minimum Score After Removals on a Tree
Min(max group xor - min group xor) by removing 2 edges from tree
05.06.2025
medium1061. Lexicographically Smallest Equivalent String
Map by smallest in group from associate s1 with s2
22.03.2025
medium2685. Count the Number of Complete Components
Count fully connected components
20.03.2025
hard3108. Minimum Cost Walk in Weighted Graph
Min AND of path weights manipulation
31.01.2025
hard827. Making A Large Island
Max area after filling one empty 2D grid cell find
29.01.2025
medium684. Redundant Connection
First edge making a cycle in graph find
23.01.2025
medium1267. Count Servers that Communicate
Connected servers by row or column
29.08.2024
medium947. Most Stones Removed with Same Row or Column
Count islands of intersecting x and y
11.08.2024
hard1568. Minimum Number of Days to Disconnect Island
Min changes 1 to 0 to disconnect islands
10.08.2024
medium959. Regions Cut By Slashes
Count islands divided by '\' and '/' in 2D matrix
30.06.2024
medium1579. Remove Max Number of Edges to Keep Graph Fully Traversable
Remove extra nodes in a connected graph by type 1, 2 and 3=1+2
21.04.2024
easy1971. Find if Path Exists in Graph
Are source and destination connected in graph?
19.04.2024
medium200. Number of Islands
Count 1-islands in 0-1 a 2D matrix
24.02.2024
hard2092. Find All People With Secret
Who knows 0 and firstPerson's secret after group meetings at times: [personA, personB, time].
19.08.2023
hard1489. Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree
List of list of must-have edges and list of optional edges for Minimum Weight Minimum Spanning Tree
30.06.2023
hard1970. Last Day Where You Can Still Cross
Last day matrix connected top-bottom when flooded each day at cells[day]
04.06.2023
medium547. Number of Provinces
Count connected groups in graph.
30.04.2023
hard1579. Remove Max Number of Edges to Keep Graph Fully Traversable
Use separate Union-Find objects for Alice and for Bob
29.04.2023
hard1697. Checking Existence of Edge Length Limited Paths
for better time complexity, compress the Union-Find path uf[x] = n
28.04.2023
hard839. Similar String Groups
decrease the groups when the two groups are joined together
07.04.2023
medium1020. Number of Enclaves
We can use visited set, or modify the grid or use Union-Find.
06.04.2023
medium1254. Number of Closed Islands
DFS will solve the problem.
25.03.2023
medium2316. Count Unreachable Pairs of Nodes in an Undirected Graph
use path compression for better root time complexity
23.03.2023
medium1319. Number of Operations to Make Network Connected
for the better time complexity of the findRoot use path compression: uf[x] = n
22.03.2023
medium2492. Minimum Score of a Path Between Two Cities
Connect all roads and update minimums in the Union-Find data structure. Use simple arrays for both connections and minimums.
15.01.2023
hard2421. Number of Good Paths
fun numberOfGoodPaths(vals: IntArray, edges: Array
14.01.2023
medium1061. Lexicographically Smallest Equivalent String
fun smallestEquivalentString(s1: String, s2: String, baseStr: String): String {