Task Scheduler
Try to solve the Task Scheduler problem.
We'll cover the following
Statement#
We’re given a character array, tasks, where each character represents a unique task. These tasks need to be performed by a single CPU, with each task taking one unit of time. The tasks can be performed in any order. At any given time, a CPU can either perform some task or stay idle.
For the given tasks, we are also provided with a positive integer value, n, which represents the cooling period between any two identical tasks. This means that the CPU must wait for at least n units of time before it performs the same task again. For example, if we have the tasks n = 2, then after performing the first
Given the two input values, tasks and n, find the least number of units of time the CPU will take to perform the given tasks.
Constraints:
tasks.lengthtasksconsists of uppercase English letters.n
Examples#
Let’s take a look at a few examples to get a better understanding of the problem statement:
1 of 3
2 of 3
3 of 3
Understand the problem#
Now, let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Task Scheduler
What is the minimum number of units of time if the following values are given as input?
Tasks = [A, A, A, B, B, C, C]
n = 1
3
7
8
9
Figure it out!#
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself#
Implement your solution in the following coding playground.
Solution: Merge Intervals
Solution: Task Scheduler