Back to problems

Implement max profit with K transactions (DP)

Algorithm · Citadel · Hard

Implement solution(prices, k), where prices is an integer array containing the stock price on each day, and k is the maximum number of completed buy-sell transactions you may make. A transaction is an ordered pair of zero-based day indices (buy_day, sell_day). It is valid only when buy_day < sell_day. Multiple transactions must be strictly disjoint in time, meaning they satisfy $$b_1 < s_1 < b_2 < s_2 < \cdots$$ so a new position may be opened only after the previous…

Checking your access…