Practice Problem

Best Time to Buy and Sell Stock IV

Difficulty: Hard

Find the maximum profit from at most k stock transactions, generalizing the Stock III problem to arbitrary k.