Heap / Greedy•Pattern: Greedy / Max-Heap•Medium

Task scheduler — minimum CPU intervals with cooldown

Problem Intuition & Objective

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

Time ComplexityO(T log T) — T = total tasks
Optimal
Space ComplexityO(1) (26 letters)
Memory Bounds
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
Previous ProblemFind K closest points to the originNext Problem Number of islands (connected components in grid)

System Design & Architecture Roadmap

Coding interviews are only 50% of the bar. Master High-Level Design, distributed systems, and Object-Oriented LLD.