Sliding Window Maximum

Hard · Monotonic Stack · Array · Queue · Sliding Window · Monotonic Deque

Problem

A window of width k slides across nums one position at a time. Return the largest value inside the window at each position.

Examples

Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
Output: [3,3,5,5,6,7]

One maximum per window position.

Input: nums = [1], k = 1
Output: [1]

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…