0Pricing
Competitive Programming Academy · Lesson

Sliding Window Maximum with Deque

Keep window extremes in O(n).

The Sliding Window Max

Given an array and a window size k, you want the maximum of every window as it slides right. Doing it naively is O(n times k).

A Faster Promise

With a monotonic deque you can answer every window in total O(n) time, scanning the array just once.

All lessons in this course

  1. Stacks for Matching Brackets
  2. Monotonic Stack: Next Greater Element
  3. Queues and collections.deque
  4. Sliding Window Maximum with Deque
← Back to Competitive Programming Academy