Problem · Array

Maximum Server Processing Time

Learn this problem
HardVisa logoVisaNEW GRADOA

Problem statement

You are given numTasks tasks and numServer servers.

The tasks must be assigned to the servers under the following conditions:

  • Each server is assigned a contiguous block of tasks.
  • Every task is assigned to exactly one server.
  • Each server must be assigned at least m tasks.

The processing time of task i is processTime[i].

For any server, its processing time is the sum of the m largest processing times among the tasks assigned to that server.

The servers work sequentially: one server completes all of its assigned tasks before the next server begins.

Determine the maximum total processing time required for all servers to complete all tasks.

Complete the function getMaximumProcessingTime. The array processTime contains the processing times of the tasks, numServer is the number of servers, and m is the minimum number of tasks assigned to each server. Here, numTasks = processTime.length. Return the maximum total processing time.

Function

getMaximumProcessingTime(processTime: int[], numServer: int, m: int) → long

Examples

Example 1

processTime = [1, 3, 5, 2, 7, 1, 5, 9]numServer = 3m = 2return = 31

Here, numTasks = 8. A maximum-total assignment is:

  • Server 1 handles tasks 1, 2, and 3. Its two largest processing times are 3 and 5, so its processing time is 8.
  • Server 2 handles tasks 4, 5, and 6. Its two largest processing times are 2 and 7, so its processing time is 9.
  • Server 3 handles tasks 7 and 8. Its two largest processing times are 5 and 9, so its processing time is 14.

The total processing time is 8 + 9 + 14 = 31. Thus, the maximum total processing time is 31.

More Visa problems

drafts saved locally
public long getMaximumProcessingTime(int[] processTime, int numServer, int m) {
  // write your code here
}
processTime[1, 3, 5, 2, 7, 1, 5, 9]
numServer3
m2
expected31
checking account