Task Scheduling
Updated
Problem 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 JP Morgan Chase interview questions
- Longest Consecutive SequencePHONE SCREEN · Seen Nov 2026
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU CacheONSITE INTERVIEW · Seen Nov 2026
- Find Total CostOA · Seen Oct 2026
- Minimum Meeting RoomsOA · Seen Oct 2026
- Count Dropped RequestsOA · Seen Oct 2026
- Maximize Binary XOR with a Set-Bit LimitPHONE SCREEN · Seen Oct 2026
- Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
- Substring RemovalOA · Seen Oct 2026
- Maximum Game Board ScoreOA · Seen Sep 2026
Similar questions at other companies
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
- Minimum Meeting RoomsSentry · PHONE SCREENSentry interview questions
- Minimum Cars for Rental RequestsGoogle · OA · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Maximum Compatible Time WindowsIBM · OAIBM interview questions
- Package Delivery SystemAmazon · OA
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- Minimum Markers to Clear Line SegmentsHSBC · OAHSBC interview questions
- Process SchedulerGoldman Sachs · OAGoldman Sachs interview questions
JP Morgan Chase interview experiences
- JPMorgan Chase Experienced SWE Java Interview: 1 Experience
- JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
- JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
- JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
- JP Morgan Chase Data and AI Intern Superday: 11 Experiences
- JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)