Best profit with at most two trades
Asked at Citadel
Given daily prices, complete at most two buy-then-sell trades (you must sell before buying again) to maximize total profit.
prices = [1, 2, 4, 2, 5, 7, 2, 4, 9, 0]
-> 13 # buy 1 sell 7 (6), buy 2 sell 9 (7)
Return the maximum profit. Aim for time, space.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.