Best Time to Buy and Sell Stock IV
Problem
Maximise profit from at most k non-overlapping buy-sell transactions on a series of daily prices (you must sell before buying again).
Input / Output
- Input: integer
kand an integer arrayprices. - Output: the maximum achievable profit.
Constraints
pricesup to 1000 long,kup to 100 — but handlek >= n/2(effectively unlimited transactions) as a special case or the DP blows space needlessly.
Example
k = 2, prices = [3,2,6,5,0,3]->7(buy 2 sell 6, buy 0 sell 3).
asked …