Challenge: Cycle Detection in a Directed Graph
If you are given a graph with all the information about its vertices and edges, can you write a code to detect a cycle? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first.
We'll cover the following
Problem Statement #
In this problem, you have to implement the detectCycle()
method to take a graph as input and detect a cycle in it. A cycle is formed when a few vertices are connected in such a way that they make a loop. An illustration is provided below for a better understanding:
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.