Leetcode 1701 - Average Waiting Time [9/7/24]
HTML-код
- Опубликовано: 7 июл 2024
- Time Taken: ~15 mins
Tag: LeetCode Medium
Concept: Simulation
High-level ideas:
Traverse through customers array in order:
For current customer, calculate the waiting time, which is addition of:
Preparation time for current customer:
Second value
Waiting time before current customer is served:
If “currTime” is less than or equal “custArrivalTime” (first value), waiting time is 0
Else waiting time is “currTime” - “custArrivalTime”
Add above value to “totalTimeCounter”
Update currTime to be the time where the current customer is done being served.
Calculate answer for average waiting time by dividing “totalTimeCounter” by number of customers.