Count Connected Components (Union-Find)

Asked at Amazon · Coding Questions · Difficulty: Medium · Last asked May 22, 2026

Given items joined by transitive 'same group' relations (products in a category, or graph edges), count the distinct groups and, in some variants, each group's size or whether an edge closes a cycle.

Loading the problem…