Maximize Sum of Processed Times
Updated
Problem statement
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. The processes are assigned one at a time, in order from i = 0 to i = n-1. When it is the (i)th process's turn, one of the following operations must be performed:
- The (i)th process is assigned to the core c, and the latch is given to the other core.
- The (i)th process is assigned to the other core, and the latch is retained by the core c.
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 an array [S1, S2], where S1 is the total time of the processes assigned to the first core and S2 is the total time of the processes assigned to the second core.
Function
maximizeSumOfProcessedTimes(time: int[]) → int[]
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 [S1, S2], the total time assigned to the first core and to the second core
Examples
Example 1
time = [10, 21, 10, 21, 10]return = [41, 31]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
Constraints
1 ≤ n ≤ 1051 ≤ time[i] ≤ 104
More Agoda interview questions
- Sort Ones, Twos, and Threes In PlacePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Can Place FlowersPHONE SCREEN · Seen Nov 2026
- Reverse Words in a StringPHONE SCREEN · Seen Nov 2026
- Molecular Weight of a Grouped FormulaONSITE INTERVIEW · Seen Oct 2026
- Disk Space Window AnalyzerPHONE SCREEN · Seen Sep 2026
- Shortest Subarray With the Full DegreePHONE SCREEN · Seen Sep 2026
- Enumerate Weekly Work SchedulesPHONE SCREEN · Seen Sep 2026
- Count Values Appearing Exactly OncePHONE SCREEN · Seen Sep 2026
- Longest All-Present Attendance StreakPHONE SCREEN · Seen Sep 2026
- Chemical Formula WeightPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
- Split Array Largest SumAuxoAI · OA
- Get Minimum IncrementIBM · OAIBM interview questions
- Binary Tree CamerasAmazon · OA · PHONE SCREEN
- Minimum Satellite Data Transfer IterationsHSBC · OAHSBC interview questions
- Minimum Number of Taps to Water a GardenGoldman Sachs · OAGoldman Sachs interview questions
- Minimum Cost to Select People for Skill QuotasVisa · OAVisa interview questions
- Find Minimum Cost to Shift MachinesCisco · OACisco interview questions
- Maximize Sum of Processed TimesSalesforce · OASalesforce interview questions
- Get Process TimeLinkedIn · OALinkedIn interview questions