Quant Memo
Coding/●●●●

Trading with a daily holding cost

Asked at Jump Trading

Given daily prices, you may complete unlimited round trips (at most one share), but every day you hold a share you pay a fixed carry cost (think financing or borrow).

prices = [1, 4, 3, 8], carry = 1
-> 6           # buy@1 sell@4 (net 2), buy@3 sell@8 (net 4), one carry day each

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