Problem Description
Given an array of job durations and k workers, assign each job to exactly one worker. The working time of a worker is the sum of the jobs assigned to them, and the goal is to minimize the maximum working time across all workers. In other words, find the optimal assignment of jobs that minimizes the maximum load any worker has, and return that value.
Key Insights
- Sort the jobs in descending order for stronger pruning during backtracking.
- Use a DFS/backtracking approach to try assigning each job to a worker.
- Prune paths where the current maximum load already exceeds the best found solution.
- Avoid redundant assignments by skipping workers with identical workloads in the current recursion step.
- The constraints (up to 12 jobs) allow an exponential backtracking solution.
Space and Time Complexity
Time Complexity: Worst-case exponential in the number of jobs, O(k^n) where n is the number of jobs, though pruning helps in practice. Space Complexity: O(n) due to recursion stack and additional space for storing worker workloads.
Solution
The solution uses a backtracking (DFS) algorithm:
- First, sort the jobs in descending order to assign larger jobs earlier.
- Use recursion to try assigning each job to each worker.
- Track the maximum load among workers after each assignment.
- Prune the recursive calls if:
- The current maximum load exceeds the best (minimum) maximum load found so far.
- A worker has the same workload as a previous worker, avoiding redundant state exploration.
- Update the best found assignment when all jobs are assigned.
This approach efficiently explores the assignment possibilities while using pruning to cut off branches that cannot lead to an improved answer.