Find Minimum Cost to Shift Machines
Memo:) The original post did not specify the company associated with the question. However, we found an identical question from Cisco. While we cannot be entirely certain that the post from 01-25-2025 originated from Cisco, the matching content suggests it is shared between Cisco and another unidentified company. Therefore, we will update the Last Seen date to 01-25-2025 to reflect this.
There are n regions where some servers are hosted. The number of machines in the ith region is machineCount[i], where 0 ≤ i < n. It can get difficult to manage all the different regions, so the team decided to move some machines to exactly 3 regions, where the number of machines in the ith region 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.
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.
🩵 Thanks a squillion, spike! 🩵
1Example 1
machineCount = [2, 4, 4, 4]. Total cost for these operations = 1+1=2.
Use the 2nd, 3rd, and 4th regions as the required servers, leaving behind the 1st region.2Example 2
Constraints
Limits and guarantees your solution can rely on.