Z17

Sliding Window Maximum

Staff / Principal Engineer
Target Time: 40 - 50 Minutes
Type: ARRAY

Problem Statement & Objective

You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position, return the max sliding window.

Function Signature (Python)

sliding_window_maximum(nums: list[int], k: int) -> list[int]

Input & Output Contract

Output Rule:List of maximum values for each window position.

System Constraints

1 <= nums.length <= 10^5
-10^4 <= nums[i] <= 10^4
1 <= k <= nums.length

Example Execution Walkthrough

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

Example Test Scenarios (3)

Example 1
Input:[[1,3,-1,-3,5,3,6,7],3]
Expected Output:[3,3,5,5,6,7]
Example 2: k=1
Input:[[1],1]
Expected Output:[1]
Example 3: Negatif Değer
Input:[[1,-1],1]
Expected Output:[1,-1]
Loading Python Editor...
Input Parameters
[
  [
    1,
    3,
    -1,
    -3,
    5,
    3,
    6,
    7
  ],
  3
]
Expected Output
[
  3,
  3,
  5,
  5,
  6,
  7
]