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 array) and time each worker can work (represented by the 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.
- Java
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 elements in a array.
Time Complexity
Time complexity of for sorting both arrays and for calculating number of days required to complete all the jobs.
Space Complexity
The solution uses constant space.