Hey there and welcome back.
Let's get started with another interesting coding interview question, which is the task scheduler question.
The question reads you are given an array of CPU tasks, each represented by letters A to Z, and a
cooling time in each cycle or interval allows the completion of one task.
Tasks can be completed in any order, but there is a constraint.
Identical tasks must be separated by at least n intervals.
Due to cooling time returned the minimum number of intervals required to complete all tasks.
So this is the question at hand, and we are given a few examples so that we can thoroughly understand
the question.
So the first example over here is the input c e c e c okay.
And n is given as two.
Now when n is equal to two, it would mean that if you are doing, for example a task C, then when
you have to wait two units of time to do another task C okay, so that's what's given over here.
Identical tasks must be separated by at least n intervals due to cooling time.
So in this case n is equal to two.
And that's why two identical tasks which is in this case c and c have to be separated by two intervals
okay.
So that's the constraint in the question.
And we are asked to identify the minimum number of intervals required to complete all tasks.
So in this example we have a total of six tasks.
And n is equal to two.
And the expected output is equal to eight which is c.
Then we do task e.
Then we have to stay idle for one interval.
And then again we can do c e.
And again we stay idle for an interval and we again do c and e okay.
So that's c e idle c e idle and c e.
So this over here is a total of eight intervals because you have 12345678 okay.
So this is the question.
Now we're given one more example.
So if the input is c e c e c and n is equal to three, the output expected is equal to ten.
And because n is equal to three over here between two c tasks you have to leave three intervals for
cooling okay.
And the output is ten because c e idle idle c e idle idle c e would be the best way or the way with
the least number of intervals for completing the input tasks.
Okay, so the expected output in this case is ten.
So this is the question at hand.
Now in the next video let's discuss the approach that we can take to solve this question.