Largest Drawdown
prices lists a fund's price on consecutive days. The drawdown on day j is the highest price seen on any day up to and including day j, minus the price on day j.
Return the largest drawdown over all days. It is never negative: when no price ever falls below an earlier high, or prices is empty, return 0.
Example 1
prices [10,7,12,4,9]
returns 8
The high is 10, then 12 from day 2 on. On day 3 the price is 4, which is 8 below the high of 12.
Example 2
prices [1,2,3]
returns 0
Prices only rise, so every day is at its own high.
Constraints
0 <= len(prices) <= 100-1000 <= prices[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Left Steps to MatchEasy
- Missing RangesEasy
- Monotonic ArrayEasy
- Nearest Aligned PointEasy
- Outside InEasy
- Pascal RowEasy
- Plurality WinnerEasy
- Range Sum QueriesEasy