Pattern 22: LeetCode Interview Patterns24 sections · 736 units
Open in CourseQuiz: Counting Components
Test your understanding
Check Your Understanding
With n cities and Union-Find, how do you count the number of provinces?
- A.Count the number of edges in the graph
- B.Start with n components, subtract 1 for each successful union
- C.Count nodes where parent[i] == i
- D.Run DFS from every node and count visits