Given a set of interconnected nodes, determine whether a cycle exists within the network and identify the length of the shortest cycle.
Explanation: A cycle is present: 1 -> 2 -> 3 -> 4 -> 1, with a length of 4.
Explanation: The shortest cycle in this graph is: 1 -> 5 -> 6 -> 7 -> 8 -> 1, with a length of 5.
Explanation: No cycle exists in the given graph, as there are only two nodes connected without forming a loop.
Detect cycles in directed/undirected graphs
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak