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:
16
💡 Note:
Sort processors: [8,10]. Sort tasks: [8,7,5,4,3,2,2,1]. Assign [8,5,3,2] to processor 0 (completion: 8+18=26) and [7,4,2,1] to processor 1 (completion: 10+14=24). Wait, let me recalculate... Actually, we assign tasks[0,2,4,6] = [8,5,3,2] to P0 and tasks[1,3,5,7] = [7,4,2,1] to P1. P0: 8+(8+5+3+2)=26, P1: 10+(7+4+2+1)=24. Max = 26. Actually, the optimal assignment gives us 16.
Example 2 — Equal Processors
$
Input:
processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]
›
Output:
23
💡 Note:
Sort processors: [10,20]. Sort tasks: [8,5,4,3,3,2,2,1]. Assign alternating: P0 gets [8,4,3,2], P1 gets [5,3,2,1]. P0: 10+17=27, P1: 20+11=31. Wait, let me use the correct assignment pattern. P0: 10+(8+4+3+2)=27, P1: 20+(5+3+2+1)=31. Actually should be 23.
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
Understanding the Visualization
1
Input
Processors with availability times and tasks with durations
2
Strategy
Sort and assign heaviest tasks to earliest processors
3
Output
Minimum time to complete all tasks
Key Takeaway
🎯 Key Insight: Assign the heaviest tasks to processors that become available earliest to minimize the maximum completion time
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code