Skip to content
BASA DSA

Task Scheduler

MediumHeap / Priority Queue

Schedule unit-time tasks on one processor. Equal task labels must have at least n intervening time slots; idle slots are allowed. Return the minimum total slots to finish all tasks.

Example 1

Input
tasks = ["A","A","A","B","B"]
n = 2
Output
7

Explanation

A,B,idle,A,B,idle,A uses seven slots with two slots between A tasks.

Example 2

Input
tasks = ["A","B","A"]
n = 0
Output
3

Explanation

Zero cooldown permits all three tasks consecutively.

Example 3

Input
tasks = ["Z","Z"]
n = 4
Output
6

Explanation

Two Z tasks need four intervening idle slots and six total slots.

Constraints

  • 1 <= number of tasks <= 10000
  • Labels are uppercase English letters
  • 0 <= n <= 100

Function contractleastIntervalArguments: json, json
Loading draft…
SolutionRuns on your device
Loading draft…