PIXELBANKv9.1.0
Menu

Sliding Window Maximum

Given an array and sliding window of size k, return the maximum in each window position.

Output space-separated.

Example:

Input:
1,3,-1,-3,5,3,6,7
3
Output:
3 3 5 5 6 7
Reasoning:
  • The array is processed with a sliding window of size k=3k=3, starting from the first element.
  • For each window position, the maximum value is found:
    • Window 1: max⁡(1,3,−1)=3\max(1, 3, -1) = 3
    • Window 2: max⁡(3,−1,−3)=3\max(3, -1, -3) = 3
    • Window 3: max⁡(−1,−3,5)=5\max(-1, -3, 5) = 5
    • Window 4: max⁡(−3,5,3)=5\max(-3, 5, 3) = 5
    • Window 5: max⁡(5,3,6)=6\max(5, 3, 6) = 6
    • Window 6: max⁡(3,6,7)=7\max(3, 6, 7) = 7
  • The maximum values from each window are collected and output as space-separated values.
  • The final output is therefore: 3355673 3 5 5 6 7

Constraints:

  • 1 <= len(nums) <= 10^5
  • -10^4 <= nums[i] <= 10^4
  • 1 <= k <= len(nums)
solution.py

Test Results

0/0
Run code to see test results.
Sliding Window Maximum - Hard | PixelBank