We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
For those who are struggling with this problem: one of a possible approach is to solve it by 2 priorityQueue: all_customers, waiting_list. all_customers is sorted by arrival time, waiting_list is sorted by cooking time.
First, add all the customers to all_customers.
Then start the while loop.
If, waiting_list is empty(which will be true when (a): you first enter the loop, or (b): nobody comes when the last pizza was being cooked), pop a customer from all_customers as the next customer.
Else, pop a customer from waiting_list as the next customer.
Then pop from all_customers to waiting_list until the peek of all_customers's arrival time is later than the current pizza is done cooking.
Minimum Average Waiting Time
You are viewing a single comment's thread. Return to all comments →
For those who are struggling with this problem: one of a possible approach is to solve it by 2 priorityQueue: all_customers, waiting_list. all_customers is sorted by arrival time, waiting_list is sorted by cooking time.
Then start the while loop. If, waiting_list is empty(which will be true when (a): you first enter the loop, or (b): nobody comes when the last pizza was being cooked), pop a customer from all_customers as the next customer. Else, pop a customer from waiting_list as the next customer.
Then pop from all_customers to waiting_list until the peek of all_customers's arrival time is later than the current pizza is done cooking.
Hope it helps