Optimal Algorithmic Approach
Greedy + Max-heap: always schedule the highest-frequency available task.
Core Invariants & Edge Cases
- Always execute the most frequent remaining task
- Formula shortcut: intervals = max(taskCount, (maxFreq-1)×(n+1) + countOfMaxFreq)
- Max-heap provides the greedy choice at each step