Implement and analyze the following three problems:
-
Maximum drawdown of cumulative PnL: "What is the maximum drawdown of a cumulative PnL (profit and loss) series, and when did it occur?" Write mdd(pnl) that returns:
(a) the maximum drawdown as a negative number;
(b) the start index (just after the peak before the drawdown starts); and
(c) the end index (where the maximum drawdown ends). State time and space complexity.
-
Single-trade stock profit (LeetCode-inspired): Given an integer array prices where prices[i] is the price on day i, compute the largest profit achievable by buying once and selling on a later day. If no profitable trade exists, return 0. Design an O
(n) time, O(
-
space solution and explain the intuition.
-
Minimum coins for target amount (LeetCode-inspired): Given coin denominations coins and a target amount, return the smallest number of coins needed to reach the target, or -1 if it cannot be formed. Assume unlimited coins of each type. Provide a dynamic programming approach and analyze time and space.