Course Schedule II
Return a valid course order given prerequisites, or [] if impossible.
Examples
Input: [2,[[1,0]]]
Output: [0,1]
Input: [2,[[1,0],[0,1]]]
Output: []
Hints
Represent the courses and prerequisites as a directed graph, where an edge from `A` to `B` means `A` is a prerequisite for `B`.
Use Kahn's algorithm for topological sorting: iteratively remove nodes with zero incoming edges (sources) and update the graph until no sources remain.
If the topological order contains all `numCourses` nodes, return it; otherwise, detect a cycle and return `[]`.
Related Problems
Course Schedule II
Return a valid course order given prerequisites, or [] if impossible.