Skip to main content

2323. Find Minimum Time to Fini...

This page provides solutions for the leetcode problem 2323. Find Minimum Time to Finish All Jobs II.

Problem Explanation

The problem asks us to calculate the number of days required to complete all the jobs, given the time each job takes (represented by the jobs\text{jobs} array) and time each worker can work (represented by the workers\text{workers} array). The solution must ensure that each job is assigned to exactly one worker, and each worker completes exactly one job.

Solution

This problem can be solved using the Greedy technique. More such questions can be found here.

import java.util.Arrays;

class Solution {
public int minimumTime(int[] jobs, int[] workers) {
Arrays.sort(jobs);
Arrays.sort(workers);
int min = 0;
for(int i = 0; i < jobs.length; i++) {
int days = jobs[i] / workers[i];
if(jobs[i] % workers[i] > 0) days++;
min = Math.max(min, days);
}
return min;
}
}

Complexity

Let's say there are N\text{N} elements in a jobs\text{jobs} array.

Time Complexity

Time complexity of O(N log N)\text{O}(\text{N} \ \text{log} \ \text{N}) for sorting both arrays and O(N)\text{O}(\text{N}) for calculating number of days required to complete all the jobs.

O(N log N)\text{O}(\text{N} \ \text{log} \ \text{N})

Space Complexity

The solution uses constant space.

O(1)\text{O}(\text{1})