Maximize Sum of Processed Times
Learn this problemProblem statement
There is a dual-core processor with one process queue for each core. There are n processes, where the time to process the ith process is denoted by time(i) (1 ≤ i ≤ n). There is a latch that helps decide which process is processed by which core. Initially, the first core has the latch. Suppose the latch is currently with the cth core, where c is either 1 or 2, and the ith process needs to be assigned. Then one of the following operations must be performed:
ith process is assigned to the core c, and the latch is given to the other core.ith 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 ith 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.
Find the sum of the time of processes assigned to the first and second cores if both the cores work optimally. Return an array of two integers, where the first integer is the sum of the time of processes assigned to the first core, and the second integer is the sum of the time of processes assigned to the second core.
Function
maximizeSumOfProcessedTimes(times: int[]) → int[]Examples
Example 1
times = [10, 10, 10, 10]return = [20, 20]Example 2
times = [1, 2, 3, 4]return = [5, 5]Example 3
times = [10, 15, 20, 25, 30]return = [55, 45]Example 4
times = [45, 25, 35, 15, 45, 25]return = [115, 75]Example 5
times = [40, 20, 30, 10]return = [70, 30]Constraints
🍑🍑More Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026
- Minimum Removals to Balance ArrayOA · Seen May 2026