Minimum Processing Time - Problem
You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task must be assigned to a unique core, and each core can only be used once.
You are given an array processorTime representing the time each processor becomes available and an array tasks representing how long each task takes to complete.
Return the minimum time needed to complete all tasks.
Input & Output
Example 1 — Basic Case
$
Input:
processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]
›
Output:
26
💡 Note:
Sort processors: [8,10]. Sort tasks: [8,7,5,4,3,2,2,1]. Assign tasks[0,2,4,6] = [8,5,3,2] to processor 0 (completion: 8+18=26) and tasks[1,3,5,7] = [7,4,2,1] to processor 1 (completion: 10+14=24). Maximum completion time is 26.
Example 2 — Equal Processors
$
Input:
processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]
›
Output:
31
💡 Note:
Sort processors: [10,20]. Sort tasks: [8,5,4,3,3,2,2,1]. Assign tasks[0,2,4,6] = [8,4,3,2] to processor 0 (completion: 10+17=27) and tasks[1,3,5,7] = [5,3,2,1] to processor 1 (completion: 20+11=31). Maximum completion time is 31.
Example 3 — Single Processor
$
Input:
processorTime = [0], tasks = [1,2,3,4]
›
Output:
10
💡 Note:
One processor gets all 4 tasks: 0 + (1+2+3+4) = 10
Constraints
- 1 ≤ n ≤ 104 (where n is number of processors)
- tasks.length == 4 * n
- 1 ≤ processorTime[i] ≤ 109
- 1 ≤ tasks[i] ≤ 109
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code