FastPrepParallel Workers with a Per-Phase Barrier
Problem · Heap

Parallel Workers with a Per-Phase Barrier

Learn this problem
MediumMakeMyTrip.com logoMakeMyTrip.comFULLTIMEONSITE INTERVIEW

Problem statement

There are workers identical workers and a matrix phaseDurations, where row t contains the duration of every phase for task t. Within each phase, assign tasks in increasing task-index order to the worker that becomes available earliest; break equal-availability ties by smaller worker index. All workers begin the current phase at its global start time. No work for phase p + 1 may begin until every task finishes phase p. Return the cumulative completion time of each phase barrier.

Function

phaseBarrierCompletionTimes(workers: int, phaseDurations: int[][]) → long[]

Examples

Example 1

workers = 2phaseDurations = [[3,2],[1,4],[2,1]]return = [3,7]

Phase 0 completes at time 3. Every phase-1 task starts no earlier than time 3, and that phase completes at time 7.

Example 2

workers = 1phaseDurations = [[2,3],[4,1]]return = [6,10]

With one worker, each phase duration is the sum of its task durations.

Constraints

  • 1 <= workers <= phaseDurations.length <= 100000
  • Every row has the same positive number of phases.
  • The total number of matrix entries is at most 200000.
  • Every duration is between 0 and 10^9, inclusive.

More MakeMyTrip.com problems

drafts saved locally
public long[] phaseBarrierCompletionTimes(int workers, int[][] phaseDurations) {
    // Write your code here.
}
workers2
phaseDurations[[3,2],[1,4],[2,1]]
expected[3,7]
checking account