Task:
Given a list of the times you need to brew each coffee, return the minimum total waiting time.
-
If you have three customers with times
[4,3,2], the first customer is going to wait4minutes for his coffee, the second customer is going to wait4minutes (the time needed for the first customer to get his coffee), another2minutes (the time needed to clean the machine) and3more minutes (the time you need to brew his coffee), so in total9minutes. The third customer, by the same logic, is about to wait9minutes (for the first two customers) +2more minutes(cleaning) +2minutes (his coffee brewing time). This order of brewing the coffee will end up in a total waiting time of26minutes, but note that this may not be the minimum time needed. This time depends on the order you choose to brew the cups of coffee. -
The order in which you brew the coffee is totally up to you.
-
coffees = [3,2,5,10,9] -> 85 coffees = [20,5] -> 32 coffees = [4,3,2] -> 22
Solution:
def barista(coffees):
time, total = 0, 0
for e in sorted(coffees):
time += e
total += time
time += 2
return total
print(barista([20,5]))
Barista problem Solutions | Codewars
No comments :
Post a Comment