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^51 <= start[i] <= end[i] <= 10^9
More IBM problems
- Count Descending SubarraysOA · Seen Apr 2026
- Count Power Products in RangeOA · Seen Apr 2026
- Minimum Operations to Make Alternating Binary StringSeen Feb 2026
- Minimum Number of Non-Empty Disjoint SegmentsSeen Feb 2026
- Count Unstable ProcessesOA · Seen Feb 2026
- Longest Balanced Binary SubarrayOA · Seen Feb 2026
- Service Timeout DetectionOA · Seen Nov 2025
- Get Minimum OperationsSeen May 2025
public int getExecutionTime(int[] start, int[] end) {
// write your code here
}
start[1, 2, 8]
end[5, 6, 10]
expected9
sign in to submit