Skip to main content

Stock Trading with Cooldown

Also known as: Best Time to Buy and Sell Stock with Cooldown

Given prices[i] = stock price on day i Can buy and sell unlimited times, but must cooldown 1 day after selling Return maximum profit Example: [1,2,3,0,2] => 3 (buy@1, sell@2, cooldown, buy@0, sell@2)

Three states carry this: holding, sold today, free to buy. I move between them one day at a time and the cooldown enforces itself.

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit, and to talk with her for one hour. After that, talking comes with the $79 pack. Anyone can open the editor and run their code.

1Maximum Profit with Cooldownmedium
Based onLeetCode

Get a note when something new lands

New company guides, new problems and big changes to Coco. Rare, and you can leave any time. By joining you agree to get these emails.