You are given an array called Rates
, where rates[i]
represents the currency price on the i
th day.
You are also given an array called Strategy
, where strategy[i]
represents an operation. Each operation could be -1
for buy, 0
for hold, and 1
for sell.
You are also given k
, which is guaranteed to be an even integer.
You can change the Strategy
array like so:
k
consecutive elements.0
.1
.
Choose an optimal range to change the Strategy
array so as to maximize the profit from executing the strategy. Return this maximum profit.
The profit is defined as the sum of all selling rates minus the sum of all buying rates. For example, if rates = [2, 3, 4, 5]
and strategy = [1, 0, 0, -1]
, then your total profit would be (2 * 1) + (5 * -1) = -3
.
Example 1:
Input: strategy = [2, 3, 4, 5], rates = [1, 0, 0, -1], k = 4
Output: -3
Explanation:Note - k value in this example is temperorily missing. I will add it once find reliable source :) Your total profit would be(2 * 1) + (5 * -1) = -3
🥹

input:
output: