Given an array of CPU tasks (represented by letters) and a cooldown period n — the minimum number of units that must pass between two executions of the same task type — return the minimum number of time units the CPU needs to finish all tasks, allowing idle units when necessary.
tasks = ["A","A","A","B","B","B"], n = 28Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →A heap keeps the minimum (or maximum) element accessible in O(1), with O(log n) insert and remove. It's the tool whenever you repeatedly need "the smallest/largest remaining item" without needing everything fully sorted.
Read the full Heap / Priority Queue guide →
Original problem on LeetCode ↗