1
00:00:00,170 --> 00:00:01,940
Hey there and welcome back.

2
00:00:01,970 --> 00:00:08,960
Let's get started with another interesting coding interview question, which is the task scheduler question.

3
00:00:08,960 --> 00:00:17,510
The question reads you are given an array of CPU tasks, each represented by letters A to Z, and a

4
00:00:17,510 --> 00:00:23,690
cooling time in each cycle or interval allows the completion of one task.

5
00:00:23,720 --> 00:00:28,340
Tasks can be completed in any order, but there is a constraint.

6
00:00:28,340 --> 00:00:33,620
Identical tasks must be separated by at least n intervals.

7
00:00:33,620 --> 00:00:39,620
Due to cooling time returned the minimum number of intervals required to complete all tasks.

8
00:00:39,620 --> 00:00:44,990
So this is the question at hand, and we are given a few examples so that we can thoroughly understand

9
00:00:44,990 --> 00:00:45,530
the question.

10
00:00:45,530 --> 00:00:51,560
So the first example over here is the input c e c e c okay.

11
00:00:51,560 --> 00:00:53,870
And n is given as two.

12
00:00:53,870 --> 00:01:00,380
Now when n is equal to two, it would mean that if you are doing, for example a task C, then when

13
00:01:00,380 --> 00:01:06,530
you have to wait two units of time to do another task C okay, so that's what's given over here.

14
00:01:06,530 --> 00:01:12,380
Identical tasks must be separated by at least n intervals due to cooling time.

15
00:01:12,380 --> 00:01:14,420
So in this case n is equal to two.

16
00:01:14,420 --> 00:01:22,280
And that's why two identical tasks which is in this case c and c have to be separated by two intervals

17
00:01:22,310 --> 00:01:22,640
okay.

18
00:01:22,640 --> 00:01:24,650
So that's the constraint in the question.

19
00:01:24,650 --> 00:01:31,370
And we are asked to identify the minimum number of intervals required to complete all tasks.

20
00:01:31,370 --> 00:01:35,990
So in this example we have a total of six tasks.

21
00:01:35,990 --> 00:01:38,060
And n is equal to two.

22
00:01:38,060 --> 00:01:42,530
And the expected output is equal to eight which is c.

23
00:01:42,530 --> 00:01:43,970
Then we do task e.

24
00:01:44,000 --> 00:01:47,420
Then we have to stay idle for one interval.

25
00:01:47,420 --> 00:01:49,730
And then again we can do c e.

26
00:01:49,730 --> 00:01:54,680
And again we stay idle for an interval and we again do c and e okay.

27
00:01:54,680 --> 00:01:58,790
So that's c e idle c e idle and c e.

28
00:01:58,880 --> 00:02:06,350
So this over here is a total of eight intervals because you have 12345678 okay.

29
00:02:06,350 --> 00:02:07,520
So this is the question.

30
00:02:07,520 --> 00:02:09,560
Now we're given one more example.

31
00:02:09,560 --> 00:02:17,300
So if the input is c e c e c and n is equal to three, the output expected is equal to ten.

32
00:02:17,300 --> 00:02:24,500
And because n is equal to three over here between two c tasks you have to leave three intervals for

33
00:02:24,500 --> 00:02:25,340
cooling okay.

34
00:02:25,340 --> 00:02:34,220
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

35
00:02:34,220 --> 00:02:38,540
the least number of intervals for completing the input tasks.

36
00:02:38,540 --> 00:02:41,510
Okay, so the expected output in this case is ten.

37
00:02:41,510 --> 00:02:43,430
So this is the question at hand.

38
00:02:43,430 --> 00:02:49,160
Now in the next video let's discuss the approach that we can take to solve this question.
