Problem Description
Explanation:
To solve this problem, we need to assign tasks to processors in a way that minimizes the total processing time. We can achieve this by sorting the tasks in decreasing order of time required and assigning them to processors with the shortest available processing time.
- Sort the tasks in decreasing order of processing time.
- Sort the processors in increasing order of availability time.
- Assign tasks to processors in a way that minimizes the total processing time.
- Calculate the time taken by each processor to complete all assigned tasks.
- Return the maximum of the two processor times as the final result.
Time Complexity: O(n log n) where n is the number of processors. Space Complexity: O(n) for storing sorted tasks.
:
Solutions
class Solution {
public int minProcessingTime(int[] processorTime, int[] tasks) {
Arrays.sort(tasks);
Arrays.sort(processorTime);
int n = processorTime.length;
int totalTime1 = 0;
int totalTime2 = 0;
for (int i = 0; i < n; i++) {
totalTime1 = Math.max(totalTime1, processorTime[i] + tasks[i]);
totalTime2 = Math.max(totalTime2, processorTime[i] + tasks[i + n]);
}
return Math.max(totalTime1, totalTime2);
}
}
Loading editor...