You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To solve the problem of calculating the average waiting time for customers in a restaurant, we use a simple iterative approach. The key steps involve simulating the process of serving each customer and calculating the total waiting time.
3
+
4
+
Approach
5
+
Input Handling:
6
+
7
+
customers is a 2D array where each element is an array representing a customer's arrival time and cooking time.
8
+
Initialization:
9
+
10
+
N stores the number of customers.
11
+
serviceTime is initialized to the sum of the arrival time and cooking time of the first customer.
12
+
totalWait is initialized to the waiting time of the first customer.
13
+
Loop Through Customers:
14
+
15
+
For each customer from the second one onwards:
16
+
Check if the chef needs to wait for the customer to arrive.
17
+
Update serviceTime to include the cooking time of the current customer.
18
+
Calculate the waiting time for the current customer and add it to totalWait.
19
+
Calculate and Return Average:
20
+
21
+
Divide totalWait by N to get the average waiting time.
0 commit comments