Best Time to Buy And Sell Stock With Cooldown
Trade one share at a time with unlimited transactions. After selling, the next day is a cooldown during which you cannot buy. Return the maximum total profit; ending with no share is allowed.
Example 1
prices = [1,2,3,0,2]3Explanation
Buy at 1, sell at 2, cool down, then buy at 0 and sell at 2 for total 3.
Example 2
prices = [5,4,3]0Explanation
Falling prices make doing nothing optimal.
Example 3
prices = [1,4]3Explanation
Buy at 1 and sell at 4 for profit 3.
Constraints
- 1 <= len(prices) <= 5000
- Prices are 0..1000
Function contract
maxProfitArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[1,2,3,0,2]