Find Minimum Time to Finish All Jobs II - Problem
You are given two 0-indexed integer arrays jobs and workers of equal length, representing a perfect job assignment scenario.
The Problem: You need to assign each job to exactly one worker such that:
jobs[i]represents the time needed to complete the i-th jobworkers[j]represents the daily working capacity of the j-th worker- Each job must be assigned to exactly one worker
- Each worker gets exactly one job
Goal: Find the minimum number of days needed to complete all jobs after optimal assignment.
Example: If we have jobs [3, 2, 3] and workers [1, 2, 3], the optimal assignment pairs the longest job with the most capable worker to minimize the maximum completion time.
Input & Output
example_1.py โ Basic Assignment
$
Input:
jobs = [3, 2, 3], workers = [1, 2, 3]
โบ
Output:
2
๐ก Note:
Optimal assignment: Job[3,3,2] โ Worker[3,2,1] gives max(1,2,2) = 2 days
example_2.py โ Equal Capacity
$
Input:
jobs = [1, 1], workers = [1, 1]
โบ
Output:
1
๐ก Note:
All jobs take 1 day regardless of assignment, so minimum is 1 day
example_3.py โ Large Job Difference
$
Input:
jobs = [5, 1], workers = [1, 5]
โบ
Output:
1
๐ก Note:
Assign job 5 to worker 5 (1 day) and job 1 to worker 1 (1 day) = 1 day total
Visualization
Tap to expand
Understanding the Visualization
1
List All Orders
We have dishes of varying complexity and chefs with different skill levels
2
Strategic Assignment
Assign the most complex dishes to the most skilled chefs
3
Minimize Wait Time
The slowest chef determines when all dishes are ready
Key Takeaway
๐ฏ Key Insight: The greedy strategy of pairing the most demanding jobs with the most capable workers minimizes the bottleneck, ensuring optimal completion time.
Time & Space Complexity
Time Complexity
O(n! ร n)
n! permutations, each taking O(n) time to evaluate
โ Quadratic Growth
Space Complexity
O(n)
Space for storing current permutation and tracking minimum
โก Linearithmic Space
Constraints
- 1 โค jobs.length โค 1000
- jobs.length == workers.length
- 1 โค jobs[i], workers[i] โค 104
- Each job must be assigned to exactly one worker
- Each worker gets exactly one job
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code