GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • LeetCodeJavascript.com
  • Star on GitHub

This view

  • Original page
  • New address

GeezerVison is showing leetcodejavascript.com — #2895 - Minimum Processing Time - LeetCode JavaScript Solutions

Back to all solutions

#2895 - Minimum Processing Time

Medium • View on LeetCode • View on GitHub
Array Sorting Greedy

Problem Description

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

/**
 * @param {number[]} processorTime
 * @param {number[]} tasks
 * @return {number}
 */
var minProcessingTime = function(processorTime, tasks) {
  tasks.sort((a, b) => b - a);
  processorTime.sort((a, b) => a - b);
  let result = 0;

  for (let i = 0; i < processorTime.length; i++) {
    for (let j = 0; j < 4; j++) {
      const taskIndex = i * 4 + j;
      result = Math.max(result, processorTime[i] + tasks[taskIndex]);
    }
  }

  return result;
};
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.