Problem 123 · Hard

Best Time to Buy and Sell Stock III

Track four states (buy1, sell1, buy2, sell2) with one pass to find the max profit from at most two transactions.

Open the interactive visualisation