1. Build an adjacency list and an in-degree array from the prerequisites. For each pair [a,b], add edge b→a and increment indegree[a].
2. Push every course with indegree=0 into a queue. These courses have no prerequisites.
3. While the queue is not empty, pop a course u, add it to the result. For each neighbor v of u, decrement indegree[v]. If indegree[v] becomes 0, push v into the queue.
4. After the loop, check the result size. If it equals n, return the result. Otherwise, a cycle exists, so return an empty array.
This runs in O(V+E) time and uses O(V+E) space.