FastPrepMinimum Time on Two Processors

Minimum Time on Two Processors

Superhuman logoSuperhuman● MediumNEW GRADINTERNOA
Learn

Problem statement

You are given an integer array data, where data[i] is the size of one indivisible data file. Every file must be assigned to exactly one of two processors.

Processor A needs processTimeA seconds for each unit of data, and Processor B needs processTimeB seconds for each unit. The two processors work in parallel.

If the total data assigned to A is sumA and the total assigned to B is sumB, all work finishes after max(sumA * processTimeA, sumB * processTimeB) seconds.

Return the minimum possible finishing time over all file assignments.

Function

getMinProcessingTime(data: int[], processTimeA: int, processTimeB: int) → int

Examples

Example 1

data = [4,4,6,2,5]processTimeA = 3processTimeB = 2return = 26

Assign the two files of size 4 to A for 24 seconds. Assign 6, 2, and 5 to B for 26 seconds. The finishing time is 26.

Example 2

data = [5,5]processTimeA = 1processTimeB = 1return = 5

Assign one file to each processor, so both finish after 5 seconds.

Constraints

  • 1 <= data.length <= 100
  • 1 <= data[i] <= 10^3
  • 1 <= processTimeA, processTimeB <= 10^3

Source note: The source slide shows the two processing rates, optimal assignment example, function signature, and constraints.

More Superhuman problems

See Superhuman hiring insights
public int getMinProcessingTime(int[] data, int processTimeA, int processTimeB) {
  // Write your code here.
}
data[4,4,6,2,5]
processTimeA3
processTimeB2
expected26
Checking account…