Leetcode 3652. Best Time to Buy and Sell Stock using Strategy
Given arrays prices and strategy, you may (once) replace any k consecutive actions by k/2 holds followed by k/2 sells to maximize the sum of strategy[i]*prices[i]; compute the maximum achievable profit. This reduces to original profit plus the maximum total "gain" over any length-k window (each day's gain = (new - old)*price, where new is 0 for the first k/2 and 1 for the last k/2), which can be found in linear time (n up to 1e5).
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Hello Interview Premium
Your account is free and you can post anonymously if you choose.