This is a verified interview question from Amazon. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Find Minimum Sum - Amazon Online Assessment Hackon" covers key patterns like Arrays.
"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 Description** Complete the `findMinimumSum` function. `findMinimumSum` has the following parameter(s): * `int power[n]`: an array of integers representing the initial computational power of the servers. ### **Returns** * `int`: the minimum possible sum of integers required to make the array non-decreasing. *(Note: The code template expects a `long` / `long_integer` return type to prevent overflow).* --- ### **Constraints** * 1 <= n <= 10^5 * 1 <= power[i] <= 10^9 --- ### **Examples** #### **Example 1** **Input:** `power = [3, 4, 1, 6, 2]` **Output:** `7` **Explanation:** There are n = 5 servers and their computational power = [3, 4, 1, 6, 2]. * Add 3 units to the subarray (2, 4). The array becomes [3, 4, 4, 9, 5]. * Add 4 units to the subarray (4, 4). The array becomes [3, 4, 4, 9, 9]. * The final arrangement of the servers is in non-decreasing order. The answer is 3 + 4 = 7. #### **Sample Case 0** **Input:** ```text 3 3 2 1 ``` *(power[] size n = 3, power = [3, 2, 1])* **Output:** `2` **Explanation:** Add 1 unit to subarray (1, 2) and 1 unit to subarray (2, 2). The final arrangement of servers is [3, 3, 3]. #### **Sample Case 1** **Input:** ```text 4 3 5 2 3 ``` *(power[] size n = 4, power = [3, 5, 2, 3])* **Output:** `3` **Explanation:** Add 3 units to subarray (2, 3). The final arrangement of servers is [3, 5, 5, 6]."
Join thousands of developers practicing for Amazon.