Sliding Window pattern

Sliding Window Maximum

Given an array nums and a window size k, return the maximum of every contiguous window of size k as the window slides from left to right. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 239
  • Hard
  • 2 approaches

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

Sliding WindowLeetCode 239

Hard

From the first idea to the best one

  1. 01 Brute force · re-scan every window O(n·k)O(1) space
  2. 02 Optimized · monotonic deque of indices O(n)O(k) space
Each approach plays step by step, with its time and space.

What you will learn

  • How to read Sliding Window Maximum and spot the sliding window pattern in it
  • Brute force · re-scan every window: O(n·k) time, O(1) space
  • Optimized · monotonic deque of indices: O(n) time, O(k) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Sliding Window

See Sliding Window Maximum run, step by step

Sign in and this page opens on the animation, with all 8 Sliding Window problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.