60. Course Schedule II

Same setup as Course Schedule: [a, b] means take b before a. Return any valid order to take all courses, or an empty array if it is impossible.

Example 1

Input: numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]]
Output: [0,1,2,3]
Explanation: Course 0 first, then 1 and 2 (any order), then 3. [0,2,1,3] is also accepted.

Example 2

Input: numCourses = 2, prerequisites = [[0,1],[1,0]]
Output: []
Explanation: The two courses depend on each other.
Hint 1

The order in which Kahn’s algorithm removes nodes is a topological order.

GraphTopological Sort