← All problems
Course Schedule II (return ordering)
Given course prerequisites as [course, prerequisite] pairs, return a valid order in which to take all n courses, or an empty array if no such order exists (i.e., the graph has a cycle).
Complexity
Time O(n+e), Space O(n+e)
Common pitfalls
- Returning partial order on cycle (must return [])
- See previous pitfalls
Your solution
Log in to save your code and track progress.