FastPrepGet Process Time
Problems/Get Process Time

Get Process Time

LinkedIn logoLinkedIn● HardINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem 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:

  • The i+1th process assigned to the core c and the latch is given to the other core.
  • The i+1th 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 aim of the time of processes assigned to the second core.

Function

getProcessTime(time: int[]) → long[]

Complete the function getProcessTime in the editor below.

getProcessTime has the following parameter:

  • int time[n]: the processing time required for each process

Returns long[2]: the sums of processing times of the first and second cores

Examples

Example 1

time = [10, 21, 10, 21, 10]return = [41, 31]
Example 1 illustration

Let's have an example, initially, the first core has the latch and the total time of processes for the first core is (10 + 21) = 31, and the total time of processes for the second core is (10 + 10 + 20). The given assignment is not optimal, the optimal time for the processes for the first core is (21+10+21)=52, and the total time of processes for the second core is (10 + 10) = 20. The given assignment is not optimal total as for the 4th process, the 2nd core assigned the process with process time = 21 to core 1 and got the 5th process with process time = 10, which is not an optimal move by core 2. The optimal move by the 2nd core would have been to assign the 4th process to itself and the 5th process to core, this would have given the total process time to the 2nd core = 31, which is better than 20.

An optimal assignment is shown.

Hence, the total time of processes for the first core is (10 + 21 + 10) = 41, and the total time of processes for the second core is (10 + 21) = 31.

Return the answer array, [41, 31].

Constraints

  • 1 ≤ n ≤ 10^5
  • 1 ≤ time[i] ≤ 10^9

More LinkedIn interview questions

  • Allocate Mailboxes with Squared DistanceONSITE INTERVIEW · Seen Nov 2026
  • Find Leaves of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Max Points on a LineONSITE INTERVIEW · Seen Nov 2026
  • Maximum Product of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
  • Maximum Sum of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
  • Merge Two Sorted ListsPHONE SCREEN · Seen Nov 2026
  • Sqrt(x)PHONE SCREEN · Seen Nov 2026
  • Total Years of Work ExperiencePHONE SCREEN · Seen Nov 2026
  • Explore an Unknown Grid and Find a PathONSITE INTERVIEW · Seen Nov 2026
  • Fire Station Response BillONSITE INTERVIEW · Seen Nov 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
  • Maximize Wall HitsOpenAI · OAOpenAI interview questions

LinkedIn interview experiences

  • LinkedIn Senior MLE Interview Questions: 1 Experience
  • LinkedIn Staff AI Engineer Phone Screens: 1 Experience
  • LinkedIn Experienced MLE Onsite: 1 Experience
  • LinkedIn Coding with AI Interview: 4 Experiences
  • LinkedIn Experienced Infrastructure SWE Onsite: 1 Experience
All LinkedIn interview questionsSee LinkedIn hiring insights
Saved
class Solution {
    public long[] getProcessTime(int[] time) {
      // write your code here
    }

}
Checking account…