Challenge: Check if a Graph is Strongly Connected

Given a graph, check whether it is strongly connected or not.

Problem statement

Implement a function that tells us whether a directed graph is strongly connected or not.

A directed graph is strongly connected if there is a path between any two pairs of vertices.

Input

The inputs are a directed graph and its source.

Output

The output is true if it’s a strongly connected graph, but it returns false otherwise.

Sample input

graph = {
    0 -> 1
    1 -> 2
    2 -> 3
    3 -> 0
    2 -> 4
    4 -> 2
}

Sample output

true

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