Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-019

Rolling Maximum

Problem

Compute the rolling maximum of a series with window size k: each output is max(series[i:i+k]) for i = 0, ..., n-k.

Return an empty list if k is not positive or k is larger than the series. A rolling maximum tracks the highest level reached recently.

Hint

The maximum over [i, i+k) can be recomputed directly for these sizes.

Test cases

case 1
in: [[1,3,2,5,4],3]
expected: [3,5,5]
case 2
in: [[2,2,2],2]
expected: [2,2]
case 3
in: [[1],1]
expected: [1]
case 4
in: [[1,2],5]
expected: []
Starter codePython
def rolling_max(series, k):
    # Your code here
    pass

4 test cases · run your code against them in the editor