Loading Similar Posts
Problem Statement:
Amazon warehouse tracks the daily stock changes of a popular product. You are given an array stockChange of length n, where stockChange[i] is the net change in inventory on the ith day (positive \rightarrow stock added, negative \rightarrow stock removed).
Your task is to determine the maximum net increase in stock over any contiguous period of at most k days. If no positive increase is possible, then the answer is 0.
Example:
n = 6
stockChange = [-3, 4, 3, -2, 2, 5]
k = 4
The optimal contiguous period is [3, -2, 2, 5] with a net change of 3 + (-2) + 2 + 5 = 8.
While the period [4, 3, -2, 2, 5] has a net change of 12, its length (5) exceeds the constraint k = 4.
Output: 8