There is a dual core processor with one queue for each core. There are n
processes, where the time to complete the (i)th process is denoted by time[i]
(0 <= i <= n-1). There is a latch that helps decide which process is completed by which core. Initially, the first core has the latch. Suppose the latch is currently with the (c)th core, where c is either 1 or 2, and the (i)th process needs to be assigned. Then one of the following operations must be performed:
The aim of each core is to have a maximum sum of time of processes with them for better performance. So, while assigning the (i)th process, the core with the latch decides the operation to be performed such that the total sum of time of processes assigned to it is maximized after all the processes are assigned.
Return the sum of time taken by the first process and the second process i.e. S1 and S2 in an array.
Function Description
Complete the function maximizeSumOfProcessedTimes
in the editor.
maximizeSumOfProcessedTimes
has the following parameter:
int[] time
: an array of integers representing the time to complete each process
Returns
int[]
: an array of two integers representing the sum of time taken by the first and second process respectively
Example 1:
Input: time = [10, 21, 10, 21, 10]
Output: [41, 31]
Explanation:Optimal assignment from both cores would be:C1 takes time[1], time[2], time[4] => Sum = 41 C2 takes time[0] and time[3] => Sum = 31
🥝🥝

input:
output: