Wait Time for the Next Customer
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.