ASAPUtils Logo ASAPUtils
Week 2

Sliding Window Maximum

Sliding Window Maximum in O(n) with a monotonic deque, with C++ and JavaScript solutions, a visualizer showing the deque, and the amortised argument that bridges into monotonic stacks.

The problem

Given an array and a window size k, return an array containing the maximum of every contiguous window of size k as the window slides from left to right.

nums = [1,3,-1,-3,5,3,6,7], k = 3 -> [3, 3, 5, 5, 6, 7]

Related Problems