Course Schedule II
MediumLeetCodeShortest Paths & Topological Sort
Approach hintTry it first, then revealHide
Use Kahn's algorithm: start from every course with in-degree zero and remove courses one at a time, lowering their neighbours' in-degrees. If fewer than n courses come out, a cycle exists and the answer is empty.