Union-Find
LeetCode 2709: Greatest Common Divisor Traversal
·3 mins
LeetCode
Hard
Math
Number-Theory
Union-Find
Sieve
Gcd
Array
LeetCode 2709 note: every pair of indices connects ⇔ one component; factor with SPF and union each number with its prime factors in Union-Find, treating 1 specially
LeetCode 3613: Minimize Maximum Component Cost
·2 mins
LeetCode
Medium
Union-Find
Graph
Sorting
Binary-Search
LeetCode 3613 note: add edges from light to heavy; the weight when exactly k components remain is the answer, and 0 when n <= k
LeetCode 3608: Minimum Time for K Connected Components
·2 mins
LeetCode
Medium
Union-Find
Graph
Sorting
Binary-Search
LeetCode 3608 note: add edges back from the largest time; the time of the first edge that drops the component count below k is the answer
LeetCode 3607: Power Grid Maintenance
·3 mins
LeetCode
Medium
Heap
Union-Find
Graph
Lazy-Deletion
LeetCode 3607 note: Union-Find groups, one min-heap per group, and lazy deletion for offline stations
LeetCode 721: Accounts Merge
·3 mins
LeetCode
Medium
Union-Find
LeetCode Problem Solving
LeetCode 990: Satisfiability of Equality Equations
·1 min
LeetCode
Daily
Medium
Union-Find
LeetCode Problem Solving
LeetCode 952: Largest Component Size by Common Factor
·2 mins
LeetCode
Hard
Math
Number-Theory
Union-Find
Hash-Table
Array
LeetCode 952 note: sharing a factor ⇔ sharing a prime factor; factor each number and union indices with the same prime factor using Union-Find, with no pairwise GCDs
LeetCode 947: Most Stones Removed with Same Row or Column
·3 mins
LeetCode
Medium
Union-Find
LeetCode Problem Solving
LeetCode 1319: Number of Operations to Make Network Connected
·2 mins
LeetCode
Medium
Union-Find
LeetCode Problem Solving
LeetCode 1202: Smallest String With Swaps
·1 min
LeetCode
Medium
Union-Find
LeetCode Problem Solving
LeetCode 684: Redundant Connection
·1 min
LeetCode
Daily
Medium
Union-Find
LeetCode Problem Solving
LeetCode 547: Number of Provinces
·3 mins
LeetCode
Medium
Union-Find
Dfs
LeetCode Problem Solving