Union-Find: The Matrix of Disjoint Sets
The Quest Begins (The "Why") I still remember the first time I stared at a LeetCode problem that asked me to count how many separate groups of friends existed in a social network. My initial instinct was to throw a nested loop at it, compare every pair, and mark visited nodes. The code worked on the tiny examples, but as soon as the input size crept past a few thousand, my solution started to feel like I was trying to bail out a sinking ship with a teaspoon. I was frustrated, not because I lacked effort, but because I was solving the wrong problem—I was treating connectivity as a series of pai
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in