Each prerequisite pair means "course must be taken before course ". This creates a directed edge in your graph. If you have and , the graph looks like . You must take course first, then , then . The order respects all dependencies.
What if you have and ? Course needs first, and course needs first. That is , a cycle. No valid ordering exists, so you return an empty array. Building the adjacency list and in-degree array from the input pairs is the first step before running Kahn's algorithm.