← All problems
Course Schedule
There are n courses labeled 0..n-1 with prerequisite pairs [course, prerequisite]. Determine whether it is possible to finish all courses — equivalently, whether the prerequisite graph has a cycle.
Complexity
Time O(n+e), Space O(n+e)
Common pitfalls
- Edge direction flipped
- DFS color method: forgetting the 'visiting' state
Your solution
Log in to save your code and track progress.