There are n courses, numbered from 0 to n − 1, and a list of pairs [a, b]: course b has to be taken before course a. Return an order in which all the courses can be taken; any such order will do. If there is none, return an empty list. Our example: 6 courses and the pairs [0, 3], [0, 5], [1, 0], [2, 5], [4, 1], [4, 2]. One answer is [3, 5, 0, 2, 1, 4].
input
numCourses: the number of courses, numbered 0 to numCourses − 1; prerequisites: pairs [a, b], each meaning course b must be taken before course a.
returns
An order to take all the courses in: each course once, and for every pair [a, b] course b before a. If there are several such orders, any of them; if there is none, [].
constraints
1 ≤ numCourses ≤ 500
0 ≤ prerequisites.length ≤ 5000
prerequisites[i] = [a, b], 0 ≤ a, b < numCourses
a ≠ b
the pairs are all different
our 13 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.