Rearrange Server Load
Learn this problemProblem statement
Given two arrays, serverCapacity, and serverLoad, each of size n, they represent the resource requirements or capacities of servers and the workload distribution across the servers. The total resource consumption is the sum of serverCapacity[i] * serverLoad[i] (0 ≤ i < n).
The task is to rearrange the array serverLoad, redistributing the load across servers to minimize the total resource consumption, ensuring their efficient utilization. Return this optimal arrangement. In scenarios with multiple solutions, return the lexicographically smallest array of serverLoad.
Function
rearrangeServerLoad(serverCapacity: int[], serverLoad: int[]) → int[]
Complete the function rearrangeServerLoad in the editor.
rearrangeServerLoad has the following parameters:
- 1.
int[] serverCapacity: an array of integers representing server capacities - 2.
int[] serverLoad: an array of integers representing server loads
Returns
int[]: the rearranged array of server loads that minimizes the total resource consumption
◝(ᵔᵕᵔ)◜ Many thanks to the amazing spike! ᯓ ᡣ𐭩
Examples
Example 1
serverCapacity = [4, 5, 6]serverLoad = [1, 2, 3]return = [3, 2, 1]
The task is to rearrange the elements in the array serverLoad to minimize the sum, serverCapacity[i] * serverLoad[i].
If serverLoad = [3, 2, 1], the total resources are calculated as follows: 4 * 3 + 5 * 2 + 6 * 1 = 28. This arrangement yields the lowest sum of resources.
Example 2
serverCapacity = [1, 2, 3, 3, 3]serverLoad = [2, 2, 4, 5, 6]return = [6, 5, 2, 2, 4]
For the rearranged serverLoad = [6, 5, 2, 2, 4], the total resource requirement is calculated as follows: = 1 * 6 + 2 * 5 + 3 * 2 + 3 * 2 + 3 * 4 = 40. 40 is the minimum possible sum after rearranging the serverLoad array, hence the answer.
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026