Algorithms, Data Structures, DFS, Bfs, Graphs.
connectedComponents = 0; for (let node = 1; node <= A; node++) { if (!visited.has(node)) { connectedComponents++; dfs(node, adjList, visited); } } return connectedComponents; } // Example usage: const A = 5; const B = [[1, 2], [3, 4], [4, 5]]; console.log(countConnectedComponents(A, B)); // Output