AlgoMaster Logo

Best Time to Buy and Sell Stock III

prices=[3, 3, 5, 0, 0, 3, 1, 4]
0 / 34
prices3day 03day 15day 20day 30day 43day 51day 64day 7buy1holding #1sell1closed #1buy2holding #2sell2closed #2track 4 running states; each day the profit cascades buy1 → sell1 → buy2 → sell2
algomaster.io
Step:Start: at most 2 buy/sell transactions on prices = [3, 3, 5, 0, 0, 3, 1, 4]