Sliding Window Maximum

Sliding Window, problem 7 of 7

Sliding Window Maximum

Hard

LC #239

dequemonotonic queuefixed window

Not attempted yet

A window of size k slides over nums from left to right, one step at a time. Return a list with the maximum of each window, in order.

Example 1

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

Example 2

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

Example 3

Input: nums = [4,-2], k = 2
Output: [4]

Constraints

  • 1 ≤ k ≤ len(nums) ≤ 10^5
  • -10^5 ≤ nums[i] ≤ 10^5

Python

Loading draft…

Test results

9 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 6 hidden

Run examples, then submit all tests.