Find Optimal Level
Learn this problemProblem statement
Amazon is dedicated to leveraging advanced methods to streamline stock movement across its distribution centers. In this scenario, you are assigned a challenge involving a specific process with a sequence of stock quantities.
More specifically, you are provided with an array of positive numbers, stockArr, containing n elements. Additionally, you are given two positive numbers, incVal and decVal, where incVal is less than or equal to decVal. You may execute the stock adjustment operation on stockArr any number of times, including not performing it at all.
The stock adjustment operation is defined as picking two distinct positions p and q in the array (0 ≤ p, q < n), increasing the value at stockArr[p] by incVal, and decreasing the value at stockArr[q] by decVal.
Our goal is to compute the highest achievable value of the minimum stock quantity in stockArr after completing all desired operations.
Note: During the adjustment process, some elements may become negative. However, once all operations have been completed, every number in stockArr must be strictly greater than 0.
Function
findOptimalLevel(stockArr: int[], incVal: int, decVal: int) → intExamples
Example 1
stockArr = [11, 1, 2]incVal = 2decVal = 3return = 3
Example 2
stockArr = [1, 5, 9]incVal = 2decVal = 2return = 5
Constraints
- 2 ≤
n≤ 2*10^5 - 1 ≤
stockArr[i]≤ 10^9 - 1 ≤
incVal≤decVal≤ 10^9
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026