Average Waiting Time | Leetcode 1701 in Java | MAANG Interview | Google Round1 | Time Interval | DSA

Ғылым және технология

the question is like There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]:
arrivali is the arrival time of the ith customer. The arrival times are sorted in non-decreasing order.
timei is the time needed to prepare the order of the ith customer.
When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input.
My approach is simple we have take care the completion time of the previous Order and then we will find Max(prevOrder, ArrivalTime) as the start Time of the current order and finish at startTime + processingTime this will give us the total time to finish the ith Order, if we deduct the Arrival time this will give us the total wait time for current customer, we will sum up the total wait time and then divide by the number of customer (the length of the customer array) which will give us the average wait time for the customers array.

Пікірлер

    Келесі