210. Course Schedule II
Practice Course Schedule II for free on NudgeCode: Medium, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Same setup as Course Schedule: numCourses courses labeled 0 to numCourses - 1, and each pair [a, b] means b must come before a. Return an order in which all courses can be taken. If that is impossible, return an empty array.
In general several orders can be valid. Every test here is built so that only one valid order exists.
Example
numCourses = 4, prerequisites = [[0,3],[3,1],[1,2]] -> [2,1,3,0]
Constraints
- 1 <= numCourses <= 2000
- 0 <= prerequisites.length <= numCourses * (numCourses - 1)
- 0 <= a, b < numCourses, a != b
- all pairs are distinct