Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Best Time to Buy and Sell Stock with Cooldown

Medium

Topics
ArrayDynamic Programming

Given daily stock prices, maximize profit with as many transactions as you like, but after you sell you must cooldown one day before buying again. Return the max profit.

Example 1

Input:  prices = [1,2,3,0,2]
Output: 3
Explanation: buy, sell, cooldown, buy, sell.

Example 2

Input:  prices = [1]
Output: 0

Constraints

  • 1 <= prices.length <= 5000
  • 0 <= prices[i] <= 1000
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access