LeetCode 621 Task Scheduler - Why Naive Fails

The trap

Try every possible ordering of tasks using backtracking.

With nn tasks, there are potentially n!n! orderings. Even with pruning, this explodes for large inputs.

Can you compute the answer without simulating every schedule?