Minimum Time on Two Processors
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) → intExamples
Example 1
data = [4,4,6,2,5]processTimeA = 3processTimeB = 2return = 26Assign 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 = 5Assign one file to each processor, so both finish after 5 seconds.
Constraints
1 <= data.length <= 1001 <= data[i] <= 10^31 <= processTimeA, processTimeB <= 10^3
Source note: The source slide shows the two processing rates, optimal assignment example, function signature, and constraints.