#3652
Best Time to Buy and Sell Stock using Strategy
specialist · 725 · lc medium +31 · 59.8% accepted · 351 likes · top 58%
Description
Arrays prices and strategy record stock prices and daily actions (-1 = buy, 0 = hold, 1 = sell). Given an even integer k, you may apply at most one modification: choose k consecutive positions in strategy, set the first k/2 to hold and the last k/2 to sell. Profit equals the sum of strategy[i] * prices[i] over all days. No budget or ownership constraints apply. Return the maximum achievable profit.
Code
1
2
3