There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai. Return the ordering of courses you should take to finish all courses. If there are multiple valid answers, return any of them. If it is impossible to finish all courses, return an empty array.
Example 1
Input: numCourses = 2, prerequisites = [[1,0]]
Output: [0,1]
Explanation: Course 1 requires course 0, so course 0 must come first: [0,1].
Example 2
Input: numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]]
Output: [0,1,2,3]
Explanation: Course 0 has no prerequisites, so it goes first. Courses 1 and 2 each need only course 0, so they come next in either order. Course 3 needs both 1 and 2, so it comes last. Both [0,1,2,3] and [0,2,1,3] are valid.
Example 3
Input: numCourses = 1, prerequisites = []
Output: [0]
Explanation: There is a single course with no prerequisites, so the order is just [0].
Start with courses that have no prerequisites. Remove them and reduce in-degree of dependent courses. Repeat until all courses are processed or a cycle is detected.
Run checks all cases above. Submit evaluates all test cases.