Find Machine Count
There are n regions where servers are hosted. The number of machines in the i-th region is given by machineCount[i], where 0 <= i < n. Managing all these regions can be challenging, so the team decided to move some machines to exactly 3 regions. The number of machines in the i-th of these 3 target regions is given by finalMachineCount[i], where 0 <= i < 3.
There are two operations that can be performed:
shiftingCost units. The now-empty region is destroyed in this operation.
Objective: Find the minimum cost to shift the machines so that any 3 regions have the counts required in finalMachineCount.
Note: It is possible that there are additional machines left at the end apart from the ones placed in the final 3 regions.
Complete the function getMinimumCost in the editor.
getMinimumCost has the following parameters:
int machineCount[]: The initial number of machines in the regions.int finalMachineCount[]: The final number of machines required in the 3 regions.int shiftingCost: The cost to move all machines from one region to another.
Returns
int: The minimum cost to move machines into 3 regions.
1Example 1
1. Increase the number of machines in the 1st and 2nd regions by 1 and 2 machines respectively. The new machineCount = [3, 5, 5, 7]. Total cost for these operations is 1 + 2 = 3.
2. Move all the machines from the 4th region to the 1st region, which takes shiftingCost = 2. The new machineCount = [10, 5, 5]. The cost of this operation is 2.
Total Cost = 3 + 2 = 5
2Example 2
Increase the number of machines in the 4th region by 1 and decrease the number of machines in the 3rd region by 1. The new machineCount = [2, 4, 4, 4]. Total cost for these operations is 1 + 1 = 2. Use the 2nd, 3rd, and 4th regions as the required servers, leaving behind the 1st region.
3Example 3
On increasing the number of machines of the 5th region by 5, the new machineCount = [5, 10, 15, 20, 20]. Total cost required for these operations = 5.
Now, moving all the machines from the 3rd region to the 1st region, which takes shiftingCost(3) dollars, the new machineCount = [20, 10, 20, 20]. Total cost required for these operations = 3.
Use the 1st, 3rd, and 4th regions as required regions, leaving behind the 2nd region. The total cost = 5 + 3 = 8.
Constraints
Limits and guarantees your solution can rely on.
3 <= n <= 10^81 <= machineCount[i], finalMachineCount[i] <= 10^61 <= shiftingCost <= 10^6