← Greedy

Pattern Recognition Drill

#143 — Task Scheduler

Medium Heaps

The Problem

Given tasks with a cooldown period n between same tasks, find the minimum time to finish all tasks.

What approach would you use?

Think about it before scrolling down.

Key Signals

Greedy

Formula: max(len(tasks), (max_freq - 1) * (n + 1) + count_of_max_freq). O(n).

Alt: Heap / Priority Queue

Max-heap + cooldown queue. Simulate rounds. O(n * tasks) but elegant.

Common Trap

The formula handles the case when total tasks exceed the frame size. Don't forget to take max with len(tasks).

← #142