Quant Memo
Coding/●●●●

Trading with a minimum holding period

Given daily prices, you may complete unlimited round trips (at most one share), but once you buy you must hold for at least two days before you are allowed to sell. So if you buy on day tt, the earliest sale is day t+2t + 2.

prices = [1, 9, 2, 3]
-> 2           # buy@1 (day 0), the 9 on day 1 is too soon to sell, sell@3 (day 3)

Return the maximum profit. Aim for O(n)O(n) time, O(1)O(1) space.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions