Find Minimum Time to Finish All Jobs - Problem

You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the i-th job.

There are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The working time of a worker is the sum of the time it takes to complete all jobs assigned to them. Your goal is to devise an optimal assignment such that the maximum working time of any worker is minimized.

Return the minimum possible maximum working time of any assignment.

Input & Output

Example 1 — Basic Case
$ Input: jobs = [3,2,3], k = 3
Output: 3
💡 Note: Assign each job to a different worker: Worker 1 gets job with time 3, Worker 2 gets job with time 2, Worker 3 gets job with time 3. Maximum working time is max(3,2,3) = 3.
Example 2 — Optimal Assignment
$ Input: jobs = [1,2,4,7,8], k = 2
Output: 11
💡 Note: Assign jobs optimally: Worker 1 gets jobs [1,2,8] with total time 11, Worker 2 gets jobs [4,7] with total time 11. Both workers finish at time 11.
Example 3 — Single Worker
$ Input: jobs = [5,3,7], k = 1
Output: 15
💡 Note: Only one worker must do all jobs: 5 + 3 + 7 = 15. The minimum possible maximum working time is 15.

Constraints

  • 1 ≤ k ≤ jobs.length ≤ 12
  • 1 ≤ jobs[i] ≤ 107

Visualization

Tap to expand
Find Minimum Time to Finish All Jobs INPUT Jobs Array (time per job) 3 Job 0 2 Job 1 3 Job 2 k = 3 Workers W1 W2 W3 Input Values: jobs = [3, 2, 3] k = 3 Total time: 8 units ALGORITHM STEPS 1 Binary Search Setup Range: [max(jobs), sum(jobs)] lo=3, hi=8 2 Check Mid Value mid = (3+8)/2 = 5 Can assign with max=5? 3 Backtracking Check Try assign jobs to k workers Prune if exceeds limit 4 Narrow Search Valid: hi = mid Invalid: lo = mid + 1 Binary Search Progress [3...5...8] mid=5 OK [3...4...5] mid=4 OK [3...3...4] mid=3 OK FINAL RESULT Optimal Job Assignment W1 --> 3 Time: 3 W2 --> 2 Time: 2 W3 --> 3 Time: 3 Maximum Working Time 3 OK - Minimized max time! Key Insight: Binary search on the answer space combined with backtracking validation. Search for minimum maximum workload where jobs can be feasibly assigned. Backtracking prunes invalid states early. Time: O(k^n * log(sum)), Space: O(n+k) | Works because answer is monotonic in feasibility. TutorialsPoint - Find Minimum Time to Finish All Jobs | Optimal Solution (Binary Search + Backtracking)
Asked in
Google 15 Facebook 12 Amazon 8 Microsoft 6
28.5K Views
Medium Frequency
~35 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen