This will cost O(k * n) space, did you get MOL error?
In fact this program cost O(k) space, there will be MOL error because the k is too large.
I think you should add these code at beginning :)
Best Time to Buy and Sell Stock IV
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.