Problem · Intervals

Process Execution Time

EasyIBMFULLTIMENEW GRADOA
See IBM hiring insights

You are given the inclusive start and end times of multiple processes. Compute the total amount of time during which at least one process is running.

Intervals are inclusive, so a process running from 1 to 5 contributes 5 - 1 + 1 = 5 units of time. Overlapping intervals should be merged before summing their lengths.

Return the total covered time.

Examples
01 · Example 1
start = [1, 2, 8]
end = [5, 6, 10]
return = 9

The first two processes merge into [1, 6] for 6 units. The third process contributes 3 more units from [8, 10]. Total = 9.

Constraints
  • 1 <= n <= 2 * 10^5
  • 1 <= start[i] <= end[i] <= 10^9
More IBM problems
drafts saved locally
public int getExecutionTime(int[] start, int[] end) {
  // write your code here
}
start[1, 2, 8]
end[5, 6, 10]
expected9
sign in to submit