Skip to main content
Back to problems
#2895
Medium Algorithms

Minimum processing time

Array Greedy Sorting
70.2% acceptance
Feb 25, 2026
282
50
You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task must be assigned to a unique core, and each core can only be used once. You are given an array processorTime representing the time each processor becomes available and an array tasks representing how long each task takes to complete. Return the minimum time needed to complete all tasks.

Solution

Rust
Time O(n log n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn min_processing_time(mut processor_time: Vec<i32>, mut tasks: Vec<i32>) -> i32 {
    processor_time.sort();
    tasks.sort_by(|a, b| b.cmp(a)); // descending
    // Assign 4 longest tasks to processor with smallest start time
    let mut ans = 0;
    for (i, &pt) in processor_time.iter().enumerate() {
      // Tasks assigned: 4*i, 4*i+1, 4*i+2, 4*i+3
      let finish = pt + tasks[4 * i]; // max is the first (largest) task
      ans = ans.max(finish);
    }
    ans
  }
}