Problem · Intervals

Get Minimum Cores

Learn this problem
EasyIBMFULLTIMEOA
See IBM hiring insights

Problem statement

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

getMinCores(start: int[], end: int[]) → int

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

Examples

Example 1

start = [1, 3, 4]end = [3, 5, 6]return = 2

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.

Constraints

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

More IBM problems

drafts saved locally
public int getMinCores(int[] start, int[] end) {
  // write your code here
}
start[1, 3, 4]
end[3, 5, 6]
expected2
checking account