Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Task Scheduler

Medium

Topics
ArrayGreedyHeapHash Table

Given a string tasks of uppercase-letter task types and a cooldown n (passed as the second value), each task takes one unit and identical tasks must be at least n units apart. Return the minimum number of units to finish all tasks.

Example 1

Input:  tasks = "AAABBB", n = 2
Output: 8

Example 2

Input:  tasks = "AAABBB", n = 0
Output: 6

Constraints

  • 1 <= tasks.length <= 10^4
  • tasks are uppercase English letters.
  • 0 <= n <= 100
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access