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
- 01 Brute force · re-scan every window O(n·k)O(1) space
- 02 Optimized · monotonic deque of indices O(n)O(k) 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
- OverviewConcept
- Max Sum Subarray of Size KLC 643 · Easy
- Max Sum of Distinct Subarrays, Size KLC 2461 · Medium
- Max Points From CardsLC 1423 · Medium
- Variable-Size WindowConcept
- Longest Substring Without RepeatsLC 3 · Medium
- Longest Repeating Character ReplacementLC 424 · Medium
- Minimum Window SubstringLC 76 · Hard
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.