Skip to content
StackDecode
Stacks & queuesExplained

Monotonic Queue

A deque kept sorted so its front is the window maximum or minimum.

Time

O(n)

Extra space

O(k)

Use it for

Sliding window extremes.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.