Problem · Greedy

Maximum Server Processing Time

Learn this problem
HardArista Networks logoArista NetworksFULLTIMEOA

Problem statement

An array processTime lists tasks in a fixed order. Split it into exactly numServers nonempty contiguous blocks, with every block containing at least m tasks.

A server's processing time is the sum of the m largest task times in its block. The servers execute sequentially, so the total processing time is the sum of their processing times. Return the maximum possible total.

Function

maxServerProcessingTime(processTime: int[], numServers: int, m: int) → long

Examples

Example 1

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

One optimal split has block scores 8, 9, and 14, totaling 31.

Example 2

processTime = [4,1,8,2]numServers = 2m = 1return = 12

The two globally largest times, 8 and 4, can be captured in separate blocks.

Example 3

processTime = [5,2,7,3]numServers = 1m = 2return = 12

With one block, the two largest task times sum to 12.

Constraints

  • 1 <= numServers, m
  • numServers * m <= processTime.length <= 2 * 10^5
  • 1 <= processTime[i] <= 10^9

More Arista Networks problems

drafts saved locally
public long maxServerProcessingTime(int[] processTime, int numServers, int m) {
    // Write your solution here.
}
processTime[1,3,5,2,7,1,5,9]
numServers3
m2
expected31
checking account