Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Customers arrive and are served one at a time, each needing some minutes: Asha 4, Ravi 2, Meera 6. Use a deque to find when each customer is finished (they start at time 0), and the average waiting time before being served.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. A queue serves in the order of arrival. Keep a clock. A customer waits until the clock reaches their turn, is served, and the clock moves on.
Check. Asha starts at 0 and finishes at 4. Ravi waits 4 and finishes at 6. Meera waits 6 and finishes at 12. The waits are 0, 4 and 6, with an average of 10 divided by 3, about 3.33.
Answer: finish at 4, 6 and 12. The average wait is about 3.33 minutes.
Log in to join the discussion.
Loading…