Leetcode Problem 1701. Average Waiting Time

1701. Average Waiting Time

Leetcode Solutions

Iterative Calculation of Waiting Times

  1. Initialize current_time to 0 and total_waiting_time to 0.
  2. Iterate through each customer in the customers array. a. If the customer's arrival time is greater than current_time, update current_time to the customer's arrival time. b. Add the customer's preparation time to current_time to get the finish time for this customer's order. c. Calculate the waiting time for the customer as current_time minus the customer's arrival time. d. Add the waiting time to total_waiting_time.
  3. After iterating through all customers, calculate the average waiting time by dividing total_waiting_time by the number of customers.
  4. Return the average waiting time.
UML Thumbnail

Cumulative Time Tracking

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...