Wait Time for the Next Customer
Updated
Problem statement
There are n servers. Server i takes exactly serviceTimes[i] time units for every customer. All servers are idle at time 0, and waitingPeople customers are ahead of you in one first-come, first-served queue.
Whenever a server is free and the queue is nonempty, the next customer starts immediately. Return the earliest time at which you start service. If a server is already available for you at time 0, return 0.
When several servers finish at the same time, all of those service slots become available at that time.
Function
waitTimeForNextCustomer(serviceTimes: int[], waitingPeople: long) → longExamples
Example 1
serviceTimes = [5,10]waitingPeople = 0return = 0Both servers are idle, so you start immediately.
Example 2
serviceTimes = [5,10]waitingPeople = 2return = 5The two waiting customers start at time zero. The five-unit server frees first.
Example 3
serviceTimes = [3,7]waitingPeople = 5return = 9Customers ahead start at times 0,0,3,6,7; you take the next slot at time 9.
Constraints
1 <= serviceTimes.length <= 100000.1 <= serviceTimes[i] <= 1000000.0 <= waitingPeople <= 10^12.
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
- Koko Eating BananasTekion · ONSITE INTERVIEWTekion interview questions
- Koko Eating BananasAmazon · ONSITE INTERVIEW
- Maximum Supplier ProfitExpedia · ONSITE INTERVIEWExpedia interview questions
- First Register Overflow TickNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Two Eggs: Minimum Worst-Case DropsApple · ONSITE INTERVIEWApple interview questions
- Find a Function Root by BisectionJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Integer Square RootMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- K-th Amount a Payout Machine Can GiveRippling · ONSITE INTERVIEWRippling interview questions
- Integer Square Root with Error ChecksBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions