LeetCode 210 Course Schedule II - Why Naive Fails

The trap

Try all permutations of courses, check which satisfies all prerequisites.

With nn courses, there are n!n! permutations. For n=2000n = 2000, this is astronomically large.

Can you build a valid ordering incrementally?