Server Power Scaling

Company: Amazon_26july

Difficulty: medium

Problem Statement

AWS provides scalable systems. A set of n servers is used for horizontally scaling an application. The goal is to arrange the servers so that their computational powers are in non-decreasing order. To do this you may repeatedly perform the following operation: Pick any contiguous segment of servers and increase the computational power of every server in that segment by the same positive integer x . The cost of this operation is x . You may perform the operation any number of times, choosing a different segment and a different x each time. Choose the operations so that, after they are applied, the computational powers are in non-decreasing order and the sum of all the chosen x values is minimum . Return that minimum possible sum. Function Description Complete the function findMinimumSum . It has the following parameter: power[n] : the computational powers of n servers. It returns a single integer: the minimum possible sum of the x values needed to make power non-decreasing. Input Format