Longest Cycle in a Graph
You're provided with a directed graph containing n nodes numbered from 0 to n - 1. Each node has at most one outgoing edge.
The graph is represented using a 0-indexed array, edges, of size n, where edges[i] indicates a directed edge from node i to node edges[i]. If there is no outgoing edge from node i, then edges[i] equals -1.
Your task is to determine and print the length of the longest cycle in the graph. If no cycle exists, print -1.
A cycle is defined as a path that starts and ends at the same node.
Ada AI
I want to discuss a solution
Help me solve this
Give more examples
What's wrong with my code?
How to use 'for loop' in javascript?
javascript (node 13.12.0)