Loading section...

Task Scheduler: Greedy + Heap

Concepts: pyTaskScheduler, pyGreedyHeap, pyPipelineScheduling

LeetCode 621: Task Scheduler. Given a list of CPU tasks with a cooldown period n, find the minimum time to execute all tasks. The greedy insight: always execute the most frequent remaining task to minimize idle time. A max-heap of frequencies implements this greedily. This is not just a LeetCode problem. Pipeline job schedulers, Airflow task prioritization, and Kafka consumer group coordination all use variants of this greedy heap scheduling. Understanding it at this level is what lets you speak intelligently about scheduling systems in the system design portion of senior interviews. The Algorithm: Most Frequent Task First The cooldown_queue (also called the waiting queue) is the key insight. When you execute a task of type A, you cannot run A again for n more intervals. So you push A's re