Tap here to switch tabs
Problem
Submissions

Problem: Best Time to Buy and Sell Stock using Strategy

med
30 min
Try to solve the Best Time to Buy and Sell Stock using Strategy problem.

Statement

You are given two integer arrays prices and strategy of the same length, along with an even integer k.

The initial total profit is defined as the sum of strategy[i] * prices[i] across all indices i.

You are allowed to perform at most one operation: select a contiguous subarray of strategy of length k, and modify its elements such that the first k2\frac{k}{2} elements are set to 00 and the remaining k2\frac{k}{2} elements are set to 11.

Return the maximum possible total profit that can be achieved.

Constraints:

  • 2≤2 \leq prices.length == strategy.length ≤105\leq 10^5

  • 1≤1 \leq prices[i] ≤105\leq 10^5

  • −1≤-1 \leq strategy[i] ≤1\leq 1

  • 2≤2 \leq k ≤\leq prices.length

  • k is even

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Best Time to Buy and Sell Stock using Strategy

med
30 min
Try to solve the Best Time to Buy and Sell Stock using Strategy problem.

Statement

You are given two integer arrays prices and strategy of the same length, along with an even integer k.

The initial total profit is defined as the sum of strategy[i] * prices[i] across all indices i.

You are allowed to perform at most one operation: select a contiguous subarray of strategy of length k, and modify its elements such that the first k2\frac{k}{2} elements are set to 00 and the remaining k2\frac{k}{2} elements are set to 11.

Return the maximum possible total profit that can be achieved.

Constraints:

  • 2≤2 \leq prices.length == strategy.length ≤105\leq 10^5

  • 1≤1 \leq prices[i] ≤105\leq 10^5

  • −1≤-1 \leq strategy[i] ≤1\leq 1

  • 2≤2 \leq k ≤\leq prices.length

  • k is even