Minimum Processing Time - Problem
Minimum Processing Time is a fascinating optimization problem that simulates real-world task scheduling scenarios.
You're managing a data center with n processors, where each processor has exactly 4 cores. You have 4n tasks to execute (exactly 4 times the number of processors), and each task must be assigned to a unique core - no core can handle multiple tasks.
You're given two arrays:
โข
โข
Your goal is to assign tasks to cores such that the maximum completion time across all processors is minimized. Each processor's completion time is determined by its availability time plus the longest task assigned to any of its 4 cores.
Example: If processor becomes available at time 8 and gets tasks [2, 1, 3, 3], its completion time is 8 + max(2,1,3,3) = 8 + 3 = 11.
You're managing a data center with n processors, where each processor has exactly 4 cores. You have 4n tasks to execute (exactly 4 times the number of processors), and each task must be assigned to a unique core - no core can handle multiple tasks.
You're given two arrays:
โข
processorTime: When each processor becomes available (length n)โข
tasks: How long each task takes to complete (length 4n)Your goal is to assign tasks to cores such that the maximum completion time across all processors is minimized. Each processor's completion time is determined by its availability time plus the longest task assigned to any of its 4 cores.
Example: If processor becomes available at time 8 and gets tasks [2, 1, 3, 3], its completion time is 8 + max(2,1,3,3) = 8 + 3 = 11.
Input & Output
example_1.py โ Basic Case
$
Input:
processorTime = [8, 10], tasks = [2, 1, 3, 3, 8, 2, 4, 6]
โบ
Output:
16
๐ก Note:
We have 2 processors and 8 tasks. Optimal assignment: Processor 1 (starts at 8) gets tasks [8,6,4,3] โ completion time = 8+8=16. Processor 2 (starts at 10) gets tasks [3,2,2,1] โ completion time = 10+3=13. Maximum is 16.
example_2.py โ Equal Start Times
$
Input:
processorTime = [5, 5, 5], tasks = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]
โบ
Output:
8
๐ก Note:
All processors start at time 5. With optimal assignment: each processor gets one task of each type [3,2,1,1], so completion time = 5+3=8 for all processors.
example_3.py โ Large Time Gaps
$
Input:
processorTime = [0, 100], tasks = [10, 10, 10, 10, 1, 1, 1, 1]
โบ
Output:
101
๐ก Note:
Processor 1 (starts at 0) gets heavy tasks [10,10,10,10] โ time = 0+10=10. Processor 2 (starts at 100) gets light tasks [1,1,1,1] โ time = 100+1=101. Maximum is 101.
Constraints
- 1 โค n โค 104 (number of processors)
- tasks.length == 4 * n (exactly 4 tasks per processor)
- 1 โค processorTime[i] โค 109
- 1 โค tasks[i] โค 109
- Each core can only process one task
Visualization
Tap to expand
Understanding the Visualization
1
Kitchen Setup
Each cooking station has 4 burners and becomes available at different times after cleaning
2
Dish Queue
You have a queue of dishes with different cooking times - some take much longer than others
3
Smart Assignment
Give the longest-cooking dishes to stations that are ready earliest
4
Optimal Service
This strategy minimizes the time when the last dish is served
Key Takeaway
๐ฏ Key Insight: The greedy approach works because pairing longest tasks with earliest processors creates the most balanced workload distribution, minimizing the maximum completion time.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code