You are given a directed graph of n nodes, where each node has at most one outgoing edge. Return the length of the longest cycle. If no cycle exists, return -1.
{
"edges": [
3,
3,
4,
2,
3
]
}3{
"edges": [
2,
-1,
3,
1
]
}-1{
"edges": [
1,
2,
0,
4,
5,
6,
3
]
}4Sign in to Run Code and Submit