Process Scheduler
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.
Complete the function getMinCores in the editor below.
getMinCores takes the following arguments:
int start[n]: the start times of processesint 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
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.