Medium
Quiz
#309 Best Time to Buy and Sell Stock with Cooldown
APPROACH
You are given an array prices where prices[i] is the price of a given stock on day i.
You may complete as many buy-sell transactions as you wish, subject to:
- You must sell before buying again.
- After selling, you cannot buy on the next day (one-day cooldown).
Return the maximum profit you can achieve.
Example 1:
Input: prices = [1,2,3,0,2]
Output: 3
Explanation: transactions = [buy, sell, cooldown, buy, sell]
Example 2:
Input: prices = [1]
Output: 0
1 of 4
1:00
What is the optimal approach for this problem?