Sliding Window Maximum
Maintain a decreasing deque of indices — O(1) window max at each step.
Problem Statement
You are given an integer array nums and a sliding window of size k which moves from the left of the array to the right. Return the max sliding window — the maximum of each window.
Examples
Example 1
Example 2
Constraints
- 1 ≤ nums.length ≤ 10⁵
- -10⁴ ≤ nums[i] ≤ 10⁴
- 1 ≤ k ≤ nums.length
Solutions
For each window position, scan k elements to find the max. O(n×k) — too slow for large inputs.
Related Concepts
Deepen your understanding with these related topics from our AI Glossary:
Want to master the core concepts?
Our free AI Glossary covers 190+ topics — from Monotonic Deque to Dynamic Programming, Machine Learning, SQL, and more. Structured learning tracks for every level.
Stuck? Ask AI to explain it step by step.
Ask Claude, GPT-4o, or Gemini to debug your code, generate test cases, or walk through the intuition. 39+ models. Pay only on days you use it — no subscription required.
Free to start · No credit card required to explore
Get Started Free