309. Best Time to Buy And Sell Stock With Cooldown

Practice Best Time to Buy And Sell Stock With Cooldown for free on NudgeCode: Medium, Dynamic Programming pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

prices[i] is a stock's price on day i. You may buy and sell as many times as you like, but you can hold at most one share at a time, and after selling you must wait one full day before buying again. Return the largest total profit.

Example

prices = [1,2,3,0,2]  ->  3   (buy 1, sell 2, cooldown, buy 0, sell 2)
prices = [1]          ->  0

Constraints