Skip to main content
Back to problems
#2323
Medium Algorithms

Find minimum time to finish all jobs ii

Array Greedy Sorting
66.0% acceptance
Mar 31, 2026
69
19
You are given two 0-indexed integer arrays jobs and workers of equal length, where jobs[i] is the amount of time needed to complete the ith job, and workers[j] is the amount of time the jth worker can work each day. Each job should be assigned to exactly one worker, such that each worker completes exactly one job. Return the minimum number of days needed to complete all the jobs after assignment.

Solution

Rust
Time O(n log n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn minimum_time(mut jobs: Vec<i32>, mut workers: Vec<i32>) -> i32 {
    // Greedy: sort both, pair largest job with largest worker
    // days for job j with worker w = ceil(j / w)
    // max over all pairs is the answer
    jobs.sort_unstable();
    workers.sort_unstable();
    jobs.iter()
      .zip(workers.iter())
      .map(|(&j, &w)| (j + w - 1) / w)
      .max()
      .unwrap_or(0)
  }
}