Trading profit with a rest day
prices[i] is the price of a share on day i. You may trade as often as you like, but you own at most one share at a time: buy it on one day, sell it on a later day, then you may buy again. After each sale you must rest for one day, so if you sell on day i you can't buy on day i + 1. Return the largest total profit you can make; not trading at all earns 0.
prices has 0 to 5,000 values, each from 0 to 10,000. Aim for one pass and O(1) extra space.
Besides the tests, one large input (4,000 days) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
max_profit([3,5,4,8,1,6])→7max_profit([1,4,2,7])→6max_profit([9,7,4,1])→0