Skip to content

2323. Find Minimum Time to Finish All Jobs II

  • Time: $O(\texttt{sort})$
  • Space: $O(\texttt{sort})$
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
class Solution {
 public:
  int minimumTime(vector<int>& jobs, vector<int>& workers) {
    int ans = 0;

    ranges::sort(jobs);
    ranges::sort(workers);

    for (int i = 0; i < jobs.size(); ++i)
      ans = max(ans, (jobs[i] - 1) / workers[i] + 1);

    return ans;
  }
};
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class Solution {
  public int minimumTime(int[] jobs, int[] workers) {
    int ans = 0;

    Arrays.sort(jobs);
    Arrays.sort(workers);

    for (int i = 0; i < jobs.length; ++i)
      ans = Math.max(ans, (jobs[i] - 1) / workers[i] + 1);

    return ans;
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Solution:
  def minimumTime(self, jobs: list[int], workers: list[int]) -> int:
    ans = 0

    jobs.sort()
    workers.sort()

    for job, worker in zip(jobs, workers):
      ans = max(ans, (job - 1) // worker + 1)

    return ans