Can’t understand the code
Explanation is too vague
Hey, in the implementation deque is used. Deque is a data structure that supports both last and front element access in O(1) time.
when you are inserting element and new element is greater than previous element , then you can remove the previous element as for every window if previous could be maximum then new element will be maximum as it is greater and comes after it.
Next thing you need to make sure is to remove the last element if it doesn’t comes in current window of k elements, for that we compare last element to i- k and if it less or equal to it we remove it.
If you still have doubts then go through method three of this link: