As in the previous question, a pair [a, b] means course b must be taken before course a. Return an order in which all courses can be taken. Many orders may exist; return the lexicographically smallest one (compare the first course, then the second, and so on). If it is impossible, return an empty list.
For num_courses = 4 and prerequisites = [[1, 0], [2, 0], [3, 1], [3, 2]] the answer is [0, 1, 2, 3].
Example 1
Input:
find_order(4, [[1, 0], [2, 0], [3, 1], [3, 2]])
Output:
[0, 1, 2, 3]
Example 2
Input:
find_order(2, [[0, 1], [1, 0]])
Output:
[]
0 <= num_courses <= 1000000 <= len(prerequisites) <= 200000No results yet
Run your code to check it against the examples, or submit to run every test.