323. Number of Connected Components In An Undirected Graph
Practice Number of Connected Components In An Undirected Graph for free on NudgeCode: Medium, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
You have n nodes labeled 0 to n - 1 and a list of undirected edges. Return the number of connected components: groups of nodes where every node can reach every other node in the group.
Example
n = 5, edges = [[0,1],[1,2],[3,4]] -> 2
Constraints
- 1 <= n <= 2000
- 0 <= edges.length <= 5000
- 0 <= a, b < n, a != b
- No edge appears twice