Problem
You get an array tasks and an integer n. Each task is an uppercase letter, and equal letters are tasks of the same kind.
A CPU is the processor of a computer. The CPU completes the tasks in time intervals. In each interval, the CPU completes one task or stays idle. Two tasks of the same kind must have at least n intervals between them.
You can complete the tasks in any order. Return the minimum number of intervals that the CPU needs to complete all the tasks.
Example 1
- Input:
- tasks = ["X","X","Y","Y","X"], n = 2
- Output:
- 7
- Explanation:
- One good order is
X, Y, idle, X, Y, idle, X.
Example 2
- Input:
- tasks = ["P","Q","R","P","Q","R"], n = 1
- Output:
- 6
- Explanation:
- The order
P, Q, R, P, Q, Rneeds no idle intervals.
Example 3
- Input:
- tasks = ["M","M","M"], n = 3
- Output:
- 9
- Explanation:
- The CPU must stay idle for 3 intervals between two
Mtasks.
Constraints
- 1 <= tasks.length <= 10^4
- tasks[i] is an uppercase English letter.
- 0 <= n <= 100
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Reorganize String
Coding · Counting · Greedy · Hash Table
- Top K Frequent Elements
Coding · Array · Bucket Sort · Counting
- Top K Frequent Words
Coding · Array · Bucket Sort · Counting
- Avoid Flood in The City
Coding · Array · Binary Search · Greedy
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 6 records
Amazon
Leetcode 621. Task Scheduler
Reported May 2, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceGoogle
Leetcode 621. Task Scheduler
Reported Jun 11, 2026 · 2 source reports
INTERN, JUNIOR
Source snapshot: Nov 12, 2026
View sourceLinkedIn
Leetcode 621. Task Scheduler
Reported Apr 30, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceNVIDIA
Leetcode 621. Task Scheduler
Reported Mar 4, 2026 · 1 source report
STAFF
Source snapshot: Nov 12, 2026