Challenge: Find All Connected Components in a Graph

Solve the challenge of finding all connected components of an undirected graph.

Problem statement

Implement a function that takes an undirected graph and prints all the connected components of a graph.

Input

An undirected graph.

Output

All connected components in a graph in a list as a list.

Sample input

Graph:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.