Quant Memo
Coding/●●●●●

Longest time underwater

Asked at Millennium, Balyasny

Drawdown depth is only half the risk story; investors also care about drawdown duration, the "time underwater." A strategy is underwater at time jj if its equity is strictly below the highest value reached before jj. The longest underwater stretch is the maximum number of consecutive periods spent below a prior peak, ending when the curve makes a new high.

equity = [100, 120, 90, 105, 60, 80, 130]
-> 4             # days at 90, 105, 60, 80 are all below the peak of 120

Return the length of the longest underwater run, in O(n)O(n) time and O(1)O(1) space.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions