algorythms
Heap / Priority Queue
LC #621Medium

Task Scheduler

Heap / Priority Queue
MetaAmazonGoogleBloomberg

Problem

Given tasks and a cooldown n, find the minimum time to execute all tasks (same task must wait n intervals between executions).

arrayheapgreedy

Constraints

  • 1 ≤ tasks.length ≤ 10⁴
  • tasks[i] is uppercase English letter
  • 0 ≤ n ≤ 100

Example

Inputtasks = ["A","A","A","B","B","B"], n = 2
Output8
Why

A→B→idle→A→B→idle→A→B. 8 intervals with cooldown n=2 between same tasks.

Hints — reveal one at a time