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.
importheapqdefminimumAverage(customers):customers.sort()n=len(customers)i=0current_time=0waiting_time=0h=[]whilei<norh:# Add all custoemrs with arrival time less or equal to current time so that no customer that arrives later is processed, as that is not valid.whilei<nandcustomers[i][0]<=current_time:heapq.heappush(h,(customers[i][1],customers[i][0]))i+=1# From the clients whose arrival time is less than the current time, extract the one whose pizza has the least preparation time.ifh:prep_time,arrival_time=heapq.heappop(h)current_time+=prep_timewaiting_time+=current_time-arrival_time# In case there are no customers to process, move to next customer. :)else:current_time=customers[i][0]returnwaiting_time// n
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Minimum Average Waiting Time
You are viewing a single comment's thread. Return to all comments →