Search⌘ K
AI Features

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.

Statement

We are given an input array, tasks, where tasks[i] =[starti,endi]= [start_i, end_i] represents the start and end times of nn tasks. Our goal is to schedule these tasks on machines given the following criteria:

  1. A machine can execute only one task at a time.

  2. A machine can begin executing a new task immediately after completing the previous one.

  3. An unlimited number of machines are available.

Find the minimum number of machines required to complete these nn tasks.

Constraints:

  • n==n == tasks.length

  • 11 \leq tasks.length 103\leq 10^3

  • 00 \leq tasksi.start << tasksi.end 104\leq 10^4

Examples

canvasAnimation-image
1 / 4

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

1.

What is the minimum number of machines required to schedule the following tasks?

[[1,7],[8,9],[3,6],[9,14],[6,7]][[1, 7], [8, 9], [3, 6], [9, 14], [6, 7]]

A.

3

B.

2

C.

5

D.

1


1 / 3

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.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5
6

Try it yourself

Implement your solution in the following coding playground.

JavaScript
usercode > main.js
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 elements
peek(); // return top element without removing
push(val); // insert element
pop(); // remove and return top element
}
*/
function minimumMachines(tasks){
// Replace this placeholder return statement with your code
return -1
}
export {
minimumMachines
}
Schedule Tasks on Minimum Machines