Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-108

Croston Method Lite

Problem

Run lite Croston's method for intermittent demand. Each nonzero demand updates a demand-size estimate with smoothing alpha, and together with the gap since the previous nonzero demand updates an interval estimate the same way. Return the ratio size / interval.

Return 0.0 if the series contains no nonzero demand.

Hint

Croston smooths demand size and inter-arrival gap separately.

Test cases

case 1
in: [[0,0,4,0,0,6,0,2],0.5]
expected: 1.4
case 2
in: [[0,0,0],0.3]
expected: 0
case 3
in: [[5],0.5]
expected: 5
case 4
in: [[0,3,0,0,6,0],0.5]
expected: 1.8
Starter codePython
def croston_method(series, alpha):
    # Your code here
    pass

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