Maximum Element | Deque

Why there is need to process first k elements seperately for this program.
Also please explain the overview of the solution of the problem instead of code.

@S18LP0113
We need to process first k seperately because if you closely observe then you will that at every step you want to answer the maximum for continuous k elements, so at the start we need to have k elements already present in deque so that in constant time operation we can tell the answer for the every next k continuous elements.

The concept/property behind sliding window is that at every step, one new element comes in our window and one elements gets out of it.
So in this question we want to answer for every k elements, then if you observe you will find out that for the next k element their is minor change i.e. one new element comes in and one gets out which is like a property for sliding window(implemented by deque easily).

Now since you can maintain every k elements, now you have to maintain it such that the front tells us about the maximum element in that k elements window. Now i think how it is maintained is clear to you because you have asked for the overview.

Feel free to ask.
Also mark this doubt as resolved if it is clear now.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.