This section collects Hot100 Union-Find templates and problems, focusing on set representatives, path compression, merge conditions, connectivity checks, and connected component counting.
LeetCode 200: Number of Islands With Union-Find
Subtitle / Summary Do not start this problem by memorizing a Union-Find template. Start from the pressure: each land cell looks like one island at first, but adjacent land cells must collapse into one connected component. Reading time: 10-12 min Tags: Hot100, Union-Find, DSU, matrix, connected components SEO keywords: LeetCode 200, Number of Islands, Union-Find, DSU, connected components Meta description: A pressure-first Python guide to LeetCode 200 that derives land-only count, 2D-to-1D ids, Union-Find merges, and the final runnable solution. Problem Requirement You are given an m x n 2D character grid: ...