PIXELBANKv9.1.0
Menu

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)
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.