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 i-th 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.
Example:
n = 3
start = [1, 3, 4]
end = [3, 6, 6]
- 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 6, and the third process runs on the first core from 4 to 6.
- Return 2, the minimum number of cores required.
Function Description
Complete the function getMinCores in the editor below.
getMinCores takes the following arguments:
- int start[n]: the start times of processes
- int end[n]: the end times of processes
Returns
- int: the minimum number of cores required
Constraints
- 1 ≤ n ≤ 10⁵
- 1 ≤ start[i] ≤ 10⁹
STDIN FUNCTION
3 → start[] size = 3
1 3 4 → start[] = [1, 3, 4]
3 → end[] size = 3
3 6 6 → end[] = [3, 6, 6]
Sample Output
2
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.
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.
Example
n = 3
start = [1, 3, 4]
end = [3, 6, 5]
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 6, and the third process runs on the first core from 4 to 6.
Return 2, the minimum number of cores required.
Function Description
Complete the function getMinCores in the editor below.
getMinCores takes the following arguments:
- int start[n]: the start times of processes
- int end[n]: the end times of processes
Returns
- int: the minimum number of cores required
Constraints
- 1 <= n <= 10⁵
- 1 <= start[i] <= end[i] <= 10⁹
STDIN FUNCTION
3 → start[] size n = 3
1 3 4 → start[] = [1, 3, 4]
3 6 5 → end[] = [3, 6, 5]
Sample 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.
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.
