Problem · Intervals
Task Scheduling
Learn this problemProblem statement
Given a set of n tasks, the task at index i, where 0 ≤ i < n, runs from time start[i] through end[i]. 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
getMinMachines(start: int[], end: int[]) → intExamples
Example 1
start = [1, 8, 3, 9, 6]end = [7, 9, 6, 14, 7]return = 3Consider 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
start = [2, 1, 5, 5, 8]end = [5, 3, 8, 6, 12]return = 3- Machine 1: [(2, 5), (8, 12)]
- Machine 2: [(1, 3), (5, 8)]
- Machine 3: [(5, 6)]
At time 5, three tasks are active because task endpoints are inclusive, so three machines are necessary and sufficient.
Example 3
start = [2, 2, 2, 2]end = [5, 5, 5, 5]return = 4- 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
More JPMorgan Chase problems
- Bitwise XOR SubsequencesOA · Seen Jul 2026
- Array ChallengeOA · Seen Jun 2026
- Minimum Cores to Handle ProcessesOA · Seen Jun 2026
- About ShippingOA · Seen Jun 2026
- Count Dropped RequestsOA · Seen Jan 2026
- Generate Table of ContentsOA · Seen Jan 2026
- Calculate Net ProfitSeen Jun 2025
- Find Total WeightSeen Jun 2025