Hard · Stacks & Queues

Find max in sliding window

Given an integer array nums and a window size k with 1 ≤ k ≤ nums.length, return the maximum of every contiguous window of k elements, in order from left to right.

Examples

Example 1

[1,3,-1,-3,5,3], k=3

Output: [3, 3, 5, 5]

Example 2

[9,11,8,5,7], k=2

Output: [11, 11, 8, 7]

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Stacks & Queues problems