PIXELBANKv9.1.0
Menu

Implement 1D max pooling with configurable kernel size and stride.

Slide a window of size pool_size across the input with step stride. At each position, output the maximum value in the window.

Return the pooled output.

Example:

Input:
x = [1, 3, 2, 5, 4, 6]
pool_size = 2
stride = 2
Output:
[3, 5, 6]
Reasoning:
  • The input list x = [1, 3, 2, 5, 4, 6] is processed with a window of size pool_size = 2 and step stride = 2.
  • The window slides across the list, and at each position, the maximum value in the window is selected:
    • Position 1: max(1,3)=3max(1, 3) = 3
    • Position 3: max(3,2)=3max(3, 2) = 3, but since the stride is 2, the next window starts at index 3 (values 3 and 5 are considered, but 3 is skipped due to stride), so max(3,5)=5max(3, 5) = 5 is considered at the next step
    • Position 5: max(5,4)=5max(5, 4) = 5, and then the window moves 2 steps forward, considering max(5,4,6)max(5, 4, 6) is not possible due to window size, so it considers max(4,6)=6max(4, 6) = 6
  • The final output is [3, 5, 6] after considering all window positions.

Constraints:

  • x: 1D list of numbers
  • pool_size: window size (integer >= 1)
  • stride: step size (integer >= 1)
  • Return 1D list of max-pooled values
solution.py

Test Results

0/0
Run code to see test results.
Max Pooling 1D - Easy | PixelBank