Compute drawdown, profit, and coin change
Problem Description
You are given a cumulative Profit and Loss (PnL) series, represented as a list or array of numerical values.
Your task is to implement a function mdd(pnl) that calculates and returns the maximum drawdown (MDD) of this series.
The maximum drawdown is defined as the largest peak-to-trough decline over a specified period. It represents the largest absolute drop from a peak in the PnL series to a subsequent trough.
The function mdd(pnl) should return a tuple or object containing:
- The maximum drawdown value (which will be a negative number).
- The start index of the period where the maximum drawdown began (i.e., the index of the peak).
- The end index of the period where the maximum drawdown concluded (i.e., the index of the trough).
Related Concepts / Hints
This problem shares conceptual similarities with:
- LeetCode 121. Best Time to Buy and Sell Stock
- LeetCode 322. Coin Change (Note: This problem's relevance to MDD is less direct but was included in the original prompt.)
AI interview prep
Core dilemma
Efficiently tracking the highest PnL value encountered so far and calculating the largest subsequent drop from that peak, while accurately identifying and storing the specific start and end indices of that maximum drawdown, all within optimal time and space complexity.
2 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Compute drawdown, profit, and coin change
Problem Description
You are given a cumulative Profit and Loss (PnL) series, represented as a list or array of numerical values.
Your task is to implement a function mdd(pnl) that calculates and returns the maximum drawdown (MDD) of this series.
The maximum drawdown is defined as the largest peak-to-trough decline over a specified period. It represents the largest absolute drop from a peak in the PnL series to a subsequent trough.
The function mdd(pnl) should return a tuple or object containing:
- The maximum drawdown value (which will be a negative number).
- The start index of the period where the maximum drawdown began (i.e., the index of the peak).
- The end index of the period where the maximum drawdown concluded (i.e., the index of the trough).
Related Concepts / Hints
This problem shares conceptual similarities with:
- LeetCode 121. Best Time to Buy and Sell Stock
- LeetCode 322. Coin Change (Note: This problem's relevance to MDD is less direct but was included in the original prompt.)