Best profit when each trade pays a fee
Asked at IMC
Given daily prices and a fixed fee charged on every completed round trip, you may buy and sell as often as you like (holding at most one share at a time).
prices = [1, 3, 2, 8, 4, 9], fee = 2
-> 8 # buy 1 sell 8 (net 5), buy 4 sell 9 (net 3)
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.