 All Problems
Sliding Window Maximum
hard
sliding window
deque
amazon
google
microsoft

Given an array nums and a sliding window of size k, return an array of the maximum value in each window as it slides from left to right.

Example 1:

Input: 1 3 -1 -3 5 3 6 7
k: 3
Output: 3 3 5 5 6 7

Constraints:

  • 1 ≤ nums.length ≤ 10⁵
  • -10⁴ ≤ nums[i] ≤ 10⁴
  • 1 ≤ k ≤ nums.length

Input format: First line: space-separated array. Second line: k.

Output format: Space-separated max values.

Run to check your code against the sample cases, or submit to run every case