A studio must record n scenes numbered 0 .. n-1. The list edges contains pairs [a, b] meaning scene a must be recorded before scene b. Among all recording orders that respect the constraints, the producer wants the lexicographically smallest one, i.e. the list that would come first when comparing lists element by element.
Return that list, or [] if the constraints cannot all be satisfied.
Examples
Input: n = 4, edges = [[3, 0], [3, 1], [2, 1]]
Output: [2, 3, 0, 1]
Explanation: 2 and 3 are available first; 2 is smaller. Then 3, after which 0 and 1 are both free.
Input: n = 3, edges = [[2, 0], [2, 1]]
Output: [2, 0, 1]
Input: n = 2, edges = [[0, 1], [1, 0]]
Output: []
Constraints
1 <= n <= 10**4,0 <= len(edges) <= 3 * 10**4- Target: O((V + E) log V) time.
Goals
- Replace the queue in Kahn's algorithm with a min-heap to break ties deterministically
- Explain why greedy smallest-ready-node yields the lexicographically smallest order