You are given an integer n representing the number of nodes,
and an array edges where edges[i] = [a, b]
indicates an undirected edge between nodes a and b.
Return the total number of connected components in the graph.
nInput: 5 [[0,1],[1,2],[3,4]] Output: 2
Input: 5 [[0,1],[1,2],[2,3],[3,4]] Output: 1
Print only the integer result.
No submissions yet.
Discuss DFS, BFS, Union-Find, and graph traversal techniques.