FastPrepFastPrep
Problem Brief

Process Scheduler

OA

Process scheduling algorithms are used by a CPU to optimally schedule the running processes. A core can execute one process at a time, but a CPU may have multiple cores. There are n processes where the ith process starts its execution at start[i] and ends at end[i], both inclusive. Find the minimum number of cores required to execute the processes.

Function Description

Complete the function getMinCores in the editor below.

getMinCores takes the following arguments:

  1. int start[n]: the start times of processes
  2. int end[n]: the end times of processes

Returns

int: the minimum number of cores required

Constraints

  • 1 ≤ n ≤ 10^5
  • 1 ≤ start[i]end[i] ≤ 10^9

1Example 1

Input
start = [1, 3, 4], end = [3, 5, 6]
Output
2
Explanation

If the CPU has only one core, the first process starts at 1 and ends at 3. The second process starts at 3. Since both processes need a processor at 3, they overlap. There must be more than 1 core.

If the CPU has two cores, the first process runs on the first core from 1 to 3, the second runs on the second core from 3 to 5, and the third process runs on the first core from 4 to 6.

Return 2, the minimum number of cores required.

2Example 2

Input
start = [1, 2, 3], end = [3, 3, 5]
Output
3
Explanation
Using 2 cores, the first and second processes finish at time 3. The third process starts at 3. Given the conflict, there must be at least 1 more core.
public int getMinCores(int[] start, int[] end) {
    // write your code here
}
Input

start

[1, 3, 4]

end

[3, 5, 6]

Output

2

Sign in to submit your solution.