Minimum CPUs for Fixed-Duration Jobs
Updated
Problem statement
You are given an array startTimes, where each value is the start time of one job, and a positive integer duration. Every job runs for exactly duration time units.
Each CPU can execute at most one job at a time. A CPU becomes available immediately when its current job ends, so a job ending at time t does not overlap a job starting at time t.
Return the minimum number of CPUs required to execute all jobs at their specified start times.
Function
minimumCpus(startTimes: int[], duration: int) → intExamples
Example 1
startTimes = [0,1,2]duration = 2return = 2The first two jobs overlap. At time 2, the job that started at 0 ends and its CPU can immediately run the third job, so two CPUs suffice.
Example 2
startTimes = [1,5,10]duration = 3return = 1Each job ends before the next one starts, so one CPU can execute all three jobs.
Example 3
startTimes = [4,4,4]duration = 1return = 3All three jobs start simultaneously, so each requires a different CPU.
Constraints
1 <= startTimes.length <= 100000.0 <= startTimes[i] <= 1000000000.1 <= duration <= 1000000000.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Meeting Rooms IIByteDance · PHONE SCREENByteDance interview questions
- Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
- Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
- Meeting Rooms IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
- Meeting Rooms IIRoblox · PHONE SCREENRoblox interview questions
- Merge K Sorted Interval ListsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Fewest Rooms for All MeetingsAdobe · PHONE SCREENAdobe interview questions