Skip to content
DeepForgeby svx
All problems
HardTime Seriests-268

Backtest Window Ranges

Problem

Generate rolling backtest window ranges as [start, end) pairs. Start at 0 and advance by step while end = start + window fits inside the series.

Return an empty list when window or step is not positive, or window exceeds the series length.

Hint

Each window is a half-open interval, consistent with Python slicing.

Test cases

case 1
in: [10,4,3]
expected: [[0,4],[3,7],[6,10]]
case 2
in: [5,5,1]
expected: [[0,5]]
case 3
in: [10,20,1]
expected: []
case 4
in: [4,2,2]
expected: [[0,2],[2,4]]
Starter codePython
def backtest_window_ranges(n, window, step):
    # Your code here
    pass

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