Your question is Nth Drawdown Calculation. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Identify the n-th longest drawdown from a list of investment returns, where the overall trend is downward.
Treat returns as simple periodic returns and rank drawdown episodes by duration, from longest to shortest. A drawdown begins when cumulative wealth falls below its previous running peak and ends when that peak is recovered. Include an unrecovered drawdown through the final observation.
Implement a function with signature find_nth_longest_drawdown(returns: list[float], n: int). Return the selected episode's start index, recovery or final index, duration, and maximum drawdown depth. Define behavior for invalid n, fewer than n episodes, and return values less than or equal to -1.