There are numCourses courses, numbered 0 to numCourses - 1. Each prerequisites[i] = [a, b] means course b must be finished before you can take course a.
Return an order in which you can take all the courses, one at a time: a list holding every course exactly once, where for every pair [a, b] course b comes before course a. If no such order exists, because some courses end up waiting on each other, return an empty list.
Often several orders work. Any valid order is accepted; the outputs below show one of them.
Courses 0 and 3 need nothing, so either can go first. Course 4 has to wait for both 3 and 1, and 1 waits for 0. [3,0,2,1,4] and [0,1,2,3,4] would be accepted too.
Course 1 needs 2 first and course 2 needs 1 first, so neither can ever start, and course 0 waits on 2 as well. Not every course can be taken, so the answer is empty.
[]
With no prerequisites, any arrangement of the three courses is a valid answer.
Constraints
1 <= numCourses <= 20000 <= prerequisites.length <= numCourses * (numCourses - 1)prerequisites[i].length == 20 <= a, b < numCoursesa != bDraw an arrow from each prerequisite to the course it unlocks. A course can be taken once everything pointing into it is done; a valid order exists exactly when the arrows have no cycle.