Problem Statement
There are nn processes to be executed, and the ii-th process has a size of processSize[i]
, where 1≤i≤n1 \leq i \leq n. Additionally, there are mm processors with different size capacities. The capacity of the ii-th processor is capacity[i]
(1≤i≤m1 \leq i \leq m).
A processor can execute a task if and only if the task size is less than or equal to its capacity, completing it in 1 second. However, a processor cannot execute a process whose size is greater than its capacity.
Each processor can execute multiple processes sequentially, but after finishing a process, it must pause for 1 second before starting the next one. Multiple processors can work on different processes simultaneously.
The goal is to find the minimum time required to execute all the processes. If it is not possible to execute all processes, return -1
.
Function Description
Complete the function findMinimumTime
with the following parameters:
processSize
: an array of integers representing the sizes of processes.capacity
: an array of integers representing the capacities of processors.
Returns:
- An integer representing the minimum time required to execute all the processes, or
-1
if it is impossible to execute all of them.
Example 1
Input:
processSize = [2, 5, 3]
capacity = [6, 2, 4]
Output:
1
Explanation:
The optimal way to assign processes is:
- The first processor (capacity
6
) executes the second process (size5
). - The second processor (capacity
2
) executes the first process (size2
). - The third processor (capacity
4
) executes the third process (size3
).
Since all processes can be executed simultaneously in 1 second, the minimum time required is 1
second.
Example 2
Input:
processSize = [3, 4, 5]
capacity = [3, 3, 3]
Output:
-1
Explanation:
- The largest process size is
5
, but the maximum processor capacity is3
. - Since there is no processor capable of handling the process of size
5
, it is impossible to execute all processes. - Hence, the output is
-1
.
我们长期稳定承接各大科技公司如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.
