Task Scheduler

Try to solve the Task Scheduler problem.

Statement

Given a character array tasks, where each character represents a unique task and a positive integer n that represents the cooling period between any two identical tasks, find the minimum number of time units the CPU will need to complete all the given tasks. Each task requires one unit to perform, and the CPU must wait for at least n units of time before it can repeat the same task. During the cooling period, the CPU can perform other tasks or remain idle.

Constraints:

  • 1≤ 1 \leq  tasks.length ≤1000 \leq 1000

  • 0≤0 \le n ≤100 \leq 100

  • tasks consists of uppercase English letters

Examples

Let’s take a look at a few examples to get a better understanding of the problem statement:

Create a free account to view this lesson.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy