Best Time to Buy and Sell Stock with Cooldown
Find the maximum profit with a cooldown period of 1 day after selling (cannot buy the next day after selling).

30:00

Best Time to Buy and Sell Stock with Cooldown
medium
Topics
Companies

Find the maximum profit with a cooldown period of 1 day after selling (cannot buy the next day after selling).

Example 1:
Input: [1,2,3,0,2]
Output: 3
Constraints:
  • 1prices.length50001 \leq \text{prices.length} \leq 5000

  • 0prices[i]10000 \leq \text{prices}[i] \leq 1000

Input
arr =[1,2,3,0,2]
1
2
3
0
2
HOLD

(holding stock)

0
SOLD

(just sold)

0
REST

(can buy)

0
State Transitions:
REST --buy--> HOLDHOLD --sell--> SOLDSOLD --cooldown--> REST
Max Profit

0

Initialize state machine

Variables
No variables to display
DepthFunction Call
Stack empty
0/22