Quant Memo
Coding/●●●●

Cooldown plus a transaction fee

Asked at Optiver

Given daily prices and a fixed fee on every completed round trip, you may trade unlimited round trips (at most one share), with a one-day cooldown after each sell.

prices = [1, 4, 0, 0, 5], fee = 1
-> 6           # buy@1 sell@4 (net 2), cooldown, buy@0 sell@5 (net 4)

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