Description
Solutions
Task Scheduling
🤘 INTERN📚RELATED PROBLEMS
Given a set of n
tasks, the ith (0 ≤ i < n) task runs from time
start[i]
through end[i]
. Implement a task scheduler required to
find the minimum number of machines required to complete the tasks. A task can be scheduled
on exactly one machine, and one machine can run only one task at a time.
Function Description
Complete the function getMinMachines
in the editor.
getMinMachines
has the following parameters:
int start[n]
: the start times of tasksint end[n]
: the end times of tasks
Returns
int
: the minimum number of machines required to run all the tasks
𓂃 ོ𓂃⊹ ࣪ ﹏𓊝﹏𓂁﹏ Credit to chizzy_elect ࿐
Example 1:
Input: start = [1, 8, 3, 9, 6], end = [7, 9, 6, 14, 7]
Output: 3
Explanation:Consider the following task schedule. Times in parentheses are the inclusive start and end times for each job. - Machine 1: [(1, 7), (8, 9)] - Machine 2: [(3, 6), (9, 14)] - Machine 3: [(6, 7)] Here, the number of machines required is 3.
Example 2:
Input: start = [2, 1, 6, 5, 8], end = [5, 8, 3, 6, 12]
Output: 3
Explanation:- Machine 1: [(2, 8)] (this is my educated guess :) - Machine 2: [(1, 3)] (this is my educated guess :) - Machine 3: [(5, 6)] (this comes from the original reference :) If you find anything wrong, plssss lmk!! Many thanks in adavance! 🫶
Example 3:
Input: start = [2, 2, 2, 2], end = [5, 5, 5, 5]
Output: 4
Explanation:- Machine 1: [(2, 5)] - Machine 2: [(2, 5)] - Machine 3: [(2, 5)] - Machine 4: [(2, 5)]
Constraints:
- 1 ≤ n ≤ 2 * 105
- 1 ≤ start[i] ≤ end[i] ≤ 109

Related Problems
Testcase
Result
Case 1
input:
output: