Schedule Batch Difference
Learn this problemProblem statement
Given n servers with their capacity, we need to schedule k batches.
Input:
n (number of servers)nk (batches)k where numServers[i] = number of servers to be included in i-th batchOutput:
For each batch calculate difference between maximum and minimum server capacity, sum it over for all k batches and return it.
Function
scheduleBatchDifference(n: int, capacity: int[], k: int, numServers: int[]) → intExamples
Example 1
n = 4capacity = [1, 2, 3, 4]k = 1numServers = [4]return = 3There is only one batch, and it includes all servers. The difference between the maximum and minimum server capacity is 4 - 1 = 3.
Example 2
n = 4capacity = [1, 2, 3, 4]k = 4numServers = [1, 1, 1, 1]return = 0Each batch includes only one server, so the difference between the maximum and minimum server capacity for each batch is 0. The total sum is 0.
Example 3
n = 4capacity = [1, 2, 3, 4]k = 2numServers = [2, 2]return = 4The first batch can include servers with capacities 1 and 4, and the second batch can include servers with capacities 2 and 3. The difference for the first batch is 4 - 1 = 3, and for the second batch is 3 - 2 = 1. The total sum is 3 + 1 = 4.
Constraints
numServers[i] == nn <= 1e6k <= nMore Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026
- Minimum Removals to Balance ArrayOA · Seen May 2026