Example 1 · empty
- Arguments
- count
0
edges[]
- Expected return
false
Test data
- Input
{"count":0,"edges":[]}- Expected output
false
func HasDependencyCycle(count int, edges [][2]int) boolExamples use {"count": ..., "edges": [[from, to], ...]}.
The runner calls your functions directly; you do not need to parse JSON.
0
[]
false
{"count":0,"edges":[]}false
4
[
[
0,
1
],
[
1,
2
],
[
2,
3
]
]false
{"count":4,"edges":[[0,1],[1,2],[2,3]]}false
3
[
[
0,
1
],
[
1,
2
],
[
2,
0
]
]true
{"count":3,"edges":[[0,1],[1,2],[2,0]]}true
5
[
[
0,
1
],
[
2,
3
],
[
3,
4
],
[
4,
2
]
]true
{"count":5,"edges":[[0,1],[2,3],[3,4],[4,2]]}true
Active nodes form the current ancestor path. An edge back to one closes a directed path into a cycle. Conversely, a directed cycle reached by the traversal must eventually encounter a vertex still active on that path. Finished nodes have already had all reachable outgoing paths examined, so reusing their result avoids false cycles and repeated work.
O(V + E) time for V=count nodes and E edges. Adjacency lists use O(V + E) storage; node states and the recursive or explicit traversal stack use O(V) additional space.
Checking execution availability…
View inputs and expected outputs. Examples do not run your code.