You are given an undirected graph with V vertices and its adjacency list. Your task is to determine the number of connected components in the graph.
A connected component is a group of vertices where every vertex is reachable from every other vertex in that group.
Input: V = 5, edges = [[0,1],[1,2],[3,4]]
Output: 2
Explanation: The graph has two connected components.
Input: V = 4, edges = [[0,1],[1,2],[2,3]]
Output: 1
Explanation: All vertices belong to a single connected component.
Input: V = 3, edges = []
Output: 3
Explanation: Each vertex forms its own connected component.
Sign in to write, run, and submit your solution against the full test suite.