diff --git a/epi_judge_python_solutions/minimum_waiting_time.py b/epi_judge_python_solutions/minimum_waiting_time.py index b0da6102b..9c5d3d245 100644 --- a/epi_judge_python_solutions/minimum_waiting_time.py +++ b/epi_judge_python_solutions/minimum_waiting_time.py @@ -2,16 +2,14 @@ from test_framework import generic_test +import itertools + def minimum_total_waiting_time(service_times: List[int]) -> int: # Sort the service times in increasing order. service_times.sort() - total_waiting_time = 0 - for i, service_time in enumerate(service_times): - num_remaining_queries = len(service_times) - (i + 1) - total_waiting_time += service_time * num_remaining_queries - return total_waiting_time + return sum(itertools.accumulate(service_times[:-1])) def minimum_total_waiting_time_pythonic(service_times):