Make Power Non-decreasing
Learn this problemProblem statement
AWS provides scalable systems. A set of n servers are used for horizontally scaling an application.
The goal is to have the computational power of the servers in non-decreasing order. To do so, you can increase the computational power of each server in any contiguous segment by x. Choose the values of x such that after the computational powers are in non-decreasing order, the sum of the x values is minimum.
Function
findMinimumSum(power: int[]) → longComplete the function findMinimumSum in the editor below.
findMinimumSum has the following parameter:
int power[n]: the computational powers ofndifferent servers
Source correction (June 28, 2026): I found another source image that shows the function name and parameter more clearly, so I fixed this version to match it. If you have the full prompt or see something off, please tell us and we'll fix it. If a clearer source shows up later, I'll update this again. 🐿️
Examples
Example 1
power = [3, 4, 1, 6, 2]return = 7There are n = 5 servers and their computational power is [3, 4, 1, 6, 2].
Add 3 units to the subarray (2, 4) and 4 units to the subarray (4, 4). The final arrangement of the servers is [3, 4, 4, 9, 9].
The answer is 3 + 4 = 7.
Example 2
power = [3, 2, 1]return = 2Add 1 unit to subarray (1, 2) and 1 unit to subarray (2, 2). The final arrangement of servers is [3, 3, 3].
🐰 Source note: I restored this official example on July 15, 2026. I'm sorry it was missing before and for the inconvenience.
Example 3
power = [3, 5, 2, 3]return = 3Add 3 units to subarray (2, 3). The final arrangement of servers is [3, 5, 5, 6].
🐣 Source note: I restored this official example on July 15, 2026. I'm sorry it was missing before and for the inconvenience.
Constraints
1 <= n <= 10^5(wherenis the length ofpower)1 <= power[i] <= 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