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.
Minimum Average Waiting Time
Minimum Average Waiting Time
Sort by
recency
|
177 Discussions
|
Please Login in order to post a comment
lol the answer is long long but the question use int, if you're getting errors change int to long long in return type and in the main function
O(nlog n)
My C++ solution, it's not the best algorithm for this problem but it fits the way to think
I get that you cannot see future orders as in the solution must be online, but what's stopping me from delaying an order and not cook any pizzas at the moment to bet on the possibility that it could get me a lower average waiting time?
Example:
Expected answer is 60/2=30, but if you delay the first customer's order and cook the second customer's pizza first you can get 57/2=28.5.
The expected solution assumes that you should always cook pizzas as long as you have an order, however I do not see this in the problem statement. Am I making any sense?
(Unrelated but what's up with the spam checker?)
EDIT: Found this comment https://www.hackerrank.com/challenges/minimum-average-waiting-time/forum/comments/124605, looks like I'm not alone :)
Python3 solution with explanation!
I always prefer to give variables more meaningful names, and provide some comments. In my solution,
currently_waiting
is a heap of customers that already placed their orders, updated every loop.