Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-123

Drawdown Duration

Problem

Compute the longest drawdown duration in a price series: the maximum number of consecutive observations strictly below the running peak. Any new high resets the counter.

Return 0 for an empty series or one that only makes new highs.

Hint

Duration counts time, not the depth of the drawdown.

Test cases

case 1
in: [[1,2,1,2,3]]
expected: 1
case 2
in: [[5,4,3,2,6]]
expected: 3
case 3
in: [[1,2,3]]
expected: 0
case 4
in: [[3,2,2,1,3]]
expected: 3
Starter codePython
def drawdown_duration(prices):
    # Your code here
    pass

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