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 many valid answers, return any of them. If it is impossible to finish all courses, return an empty array.
Topological Sort (Kahn's or DFS)
Unlike Course Schedule I, which only detects cycles, this problem requires the actual linear ordering. Using Kahn's Algorithm (BFS): 1. Calculate the in-degree of each node. 2. Add all nodes with 0 in-degree into a queue. 3. While the queue is not empty: pop a node, add it to the result, and decrement the in-degree of all its neighbors. If a neighbor reaches 0 in-degree, add it to the queue. If the final result has fewer nodes than `numCourses`, a cycle exists.