Best Time to Buy and Sell Stock IV (k Transactions)
Hard · Dynamic Programming · about 30 minutes
Asked at Google, Amazon, Coinbase.
prices[i] is a stock's price on day i. Return the maximum profit with at most k transactions (buy then sell; you can't hold more than one share at a time).