In the previous video, we came up with this pseudo code for solving this question.
Now let's think of the space and time complexity for this approach for solving the task scheduler problem.
Okay, now for this.
Let's take a look at what are the aspects in this solution that take up work.
Okay.
We can see that this aspect over here, which is traversing the tasks and calculating task frequencies,
takes up work of the order of n where n is the size of the tasks array.
And again it's o of n because we have to traverse or pass through once the elements in the tasks array.
Okay.
And then these aspects over here are just O of one time complexity operations or constant time operations
because we're just doing a few calculations.
Right.
So that's why the total time complexity of this solution is of the order of n.
Now what about the space complexity?
The space complexity of this approach is of the order of one or constant space.
Now why is this the case?
You may say that we are using space because we have an array which is used to store the frequency of
the tasks which are given to us.
But then in the question, it's mentioned that the tasks go from A to Z.
Okay, so that's a maximum of 26 different tasks.
And therefore the space of this array which is used to store the frequencies is not varying based on
the input size.
Okay.
So that's why the space complexity is just constant.
Remember O of 26 space complexity is one and the same as O of one, because we are not using up varying
space based on the input size.
So the space complexity of this solution is of the order of one.