You are given an array prices where prices[i] is the price of a given stock on the ith day.
Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times) with the following restrictions:
Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
Input: prices = [1,2,3,0,2]
Output: 3
Explanation: transactions = [buy, sell, cooldown, buy, sell]
Input: prices = [1]Output: 0
Constraints:
1 <= prices.length <= 50000 <= prices[i] <= 1000sell[i] which is the maximum profit we can have up to day i (inclusive) and must sell on i, and buy[i] for transactions where max profit up to i and must buy on i.buy and sell arrays.buy[i] and sell[i], we only need the values for i-1 and i-2.buy and sell, we maintain only variables for the last two and current states.