Unlock Order
Mediumgraphstopological sort
A skill tree has n skills numbered 0 to n - 1. Each pair [a, b] in requires means skill a must be unlocked before skill b.
Return an order that unlocks every skill exactly once and respects all requirements. When several skills are available, always unlock the one with the smallest number next, so the answer is unique. If the requirements contain a cycle, return an empty list.
Examples
Input: n = 4, requires = [[1,0],[2,0],[3,1]]
Output: [2,3,1,0]
Input: n = 2, requires = [[0,1],[1,0]]
Output: []