Schedule Tasks on Minimum Machines
Understand how to schedule multiple tasks on the least number of machines by leveraging heaps to track ongoing tasks. This lesson helps you develop a methodical approach to allocate tasks efficiently, ensuring no overlaps and using unlimited machines selectively to minimize their count.
We'll cover the following...
Statement
We are given an input array, tasks, where tasks[i]
A machine can execute only one task at a time.
A machine can begin executing a new task immediately after completing the previous one.
An unlimited number of machines are available.
Find the minimum number of machines required to complete these
Constraints:
tasks.lengthtasks.lengthtasksi.starttasksi.end
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Schedule Tasks on Minimum Machines
What is the minimum number of machines required to schedule the following tasks?
3
2
5
1
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in the following coding playground.
import { MinHeap, MaxHeap } from './Heap.js'/* The following definition is for MinHeap.You can use the same methods for MaxHeap.class MinHeap {size(); // return number of elementspeek(); // return top element without removingpush(val); // insert elementpop(); // remove and return top element}*/function minimumMachines(tasks){// Replace this placeholder return statement with your codereturn -1}export {minimumMachines}