FreeCareerPath
Build the PrimitiveMedium

Best Time to Buy and Sell Stock with Cooldown

Write `max_profit_cooldown(prices)` returning the maximum profit with unlimited transactions, except that you may not buy on the day after you sell. max_profit_cooldown([1,2,3,0,2]) -> 3 (buy 1, sell 2, cooldown, buy 0, sell 2) Model it as three states — holding, just sold, and free to buy — and write the transition into each. Once the states are named the code is mechanical; trying to reason about it without naming them is where people get lost.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Best Time to Buy and Sell Stock with Cooldown" are saved to your account — logging in takes a few seconds.

Best Time to Buy and Sell Stock with Cooldown — FreeCareerPath