AMAZON Coding Question – Solved

2 Live
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. Example: There are n = 5 servers and their computational power = [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. Function Description: Complete the function findMinimumSum in the editor below. findMinimumSum has the following parameter(s): int power[n]: the computational powers of n different servers Returns: int: the minimum possible sum of integers required to make the array non-decreasing Constraints: 1 ≀ n ≀ 10^5 1 ≀ power[i] ≀ 10^9 Input Format For Custom Testing: The first line contains an integer, n, denoting the number of elements in power. Each line i of the n subsequent lines (where 0 ≀ i < n) contains an integer describing power. Sample Case 0: Sample Input: 3 power[] size n = 3 power = [3, 2, 1] Sample Output: 1

Asked in: AMAZON

Image of the Question

Question Image Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| As an operations engineer at Amazon, you are responsible for organizing the dis… |
| Amazon Books is a retail store that sells the newly launched novel "The Story o… |
| In an Amazon analytics team, the Analysts collectively have a preference for th… |
| A foundry in Hackerland makes an alloy out of n different metals. In the manufa… |
| An array of integers is almost sorted if at most one element can be deleted fro… |
| The binary cardinality of a number is the count of 1's in its binary representa… |