You are given an integer array prices where prices[i] is the price of a given stock on day i, and an integer k.
You may complete at most k transactions. Each transaction can be one of the following two types:
Normal transaction: Buy the stock on day i and sell it on day j with i < j, achieving a profit of prices[j] prices[i].
Short selling transaction: Sell the stock on day i and buy it back on day j with i < j, achieving a profit of prices[i] prices[j].
You cannot engage in multiple transactions simultaneously. That is, you must finish your current transaction before initiating a new one.
Return the maximum profit you can achieve.
Constraints:
prices.length
prices[i]
k prices.length
You are given an integer array prices where prices[i] is the price of a given stock on day i, and an integer k.
You may complete at most k transactions. Each transaction can be one of the following two types:
Normal transaction: Buy the stock on day i and sell it on day j with i < j, achieving a profit of prices[j] prices[i].
Short selling transaction: Sell the stock on day i and buy it back on day j with i < j, achieving a profit of prices[i] prices[j].
You cannot engage in multiple transactions simultaneously. That is, you must finish your current transaction before initiating a new one.
Return the maximum profit you can achieve.
Constraints:
prices.length
prices[i]
k prices.length