Problem · Binary Search

Find Minimum Time

Learn this problem
HardRippling logoRipplingNEW GRADOA

Problem statement

There are n processes to execute. Process i has size processSize[i]. There are m processors, and processor i has capacity capacity[i].

A processor completes a process whose size is at most its capacity in 1 second. It cannot execute a process whose size exceeds its capacity.

A processor may execute multiple processes one after another, but it must pause for 1 second after completing a process before starting its next one. Different processors may work simultaneously.

Return the minimum time needed to execute every process, or -1 if completing all processes is impossible.

Function

findMinimumTime(processSize: int[], capacity: int[]) → int

Examples

Example 1

processSize = [2, 5, 3]capacity = [6, 2, 4]return = 1

The optimal assignment gives:

  • The first processor the second process
  • The second processor the first process
  • The third processor the third process

All three processors work simultaneously and finish in 1 second.

Example 2

processSize = [1, 2, 3, 4, 6]capacity = [4, 7, 4]return = 3

Assign process sizes 2 and 3 to the first processor, sizes 1 and 6 to the second processor, and size 4 to the third processor. Each processor with two processes works for 1 second, pauses for 1 second, and works for 1 more second. Therefore, all processes finish in 3 seconds.

Example 3

processSize = [2, 5, 8]capacity = [6, 7, 4]return = -1

No processor has enough capacity for the process of size 8, so completing every process is impossible.

More Rippling problems

drafts saved locally
public int findMinimumTime(int[] processSize, int[] capacity) {
  // write your code here
}
processSize[2, 5, 3]
capacity[6, 2, 4]
expected1
checking account