Problem
You get an integer array prices. The value prices[i] is the price of a stock on day i.
You can buy and sell the stock as many times as you want. You can hold at most one share at a time. So you must sell your share before you buy again.
After you sell, you cannot buy on the next day. This day of rest is the cooldown. Return the maximum profit that you can make.
Example 1
- Input:
- prices = [2,5,1,3,6]
- Output:
- 6
- Explanation:
- Buy on day 0 and sell on day 1 for a profit of 3. Rest on day 2. Buy on day 3 and sell on day 4 for a profit of 3.
Example 2
- Input:
- prices = [9,7,4]
- Output:
- 0
- Explanation:
- The price goes down every day. So the best choice is to buy nothing.
Constraints
- 1 <= prices.length <= 5000
- 0 <= prices[i] <= 1000
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Best Time to Buy and Sell Stock
Coding · Array · Dynamic Programming
- Best Time to Buy and Sell Stock II
Coding · Array · Dynamic Programming · Greedy
- Best Time to Buy and Sell Stock III
Coding
- Best Time to Buy and Sell Stock IV
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 309. Best Time to Buy and Sell Stock with Cooldown
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source