educative.io

Deque - comment

In the puzzle, the dequeue was suddenly introduced without any context. It appeared it was pointing to the result dequeue than a new dequeue introduced in the solution to cache the window.

Sample applies to the explanation and solution of the problem in the following pages.

It will be useful to explain what will be the use of dequeue and how and why elements will be pushed and popd out of it than just stating elements being added and removed.


Course: Grokking Coding Interview Patterns in Java - Learn Interactively
Lesson: Find Maximum in Sliding Window - Grokking Coding Interview Patterns in Java

hey @bee1! Thanks for pointing it out.
The algorithm uses the deque data structure to find the maximum in a window. A deque is a double-ended queue where the push and pop operations work in O(1)O(1) at both ends. It acts as our window. We will store elements in the deque in decreasing order. The front of the deque contains the index for the maximum value in that particular window.
We hope Educative has inspired you to further your learning. :blush: