Algorithms and Data Structures · Senior · Question 55 of 75

What does a monotonic deque give you in the "sliding window maximum" problem?

Explanation

The deque keeps indices of decreasing values: new values pop smaller ones from the back, and indices that left the window are dropped from the front. Every index enters and leaves once. A median needs two heaps instead.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 55

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz