calculate the minimum waiting time using a greedy algorithm reference https www youtube comwatch vsf3eio12ejs for doctests run following command python m doctest v minimumwaitingtime py the minimumwaitingtime function uses a greedy algorithm to calculate the minimum time for queries to complete it sorts the list in nondecreasing order calculates the waiting time for each query by multiplying its position in the list with the sum of all remaining query times and returns the total waiting time a doctest ensures that the function produces the correct output this function takes a list of query times and returns the minimum waiting time for all queries to be completed args queries a list of queries measured in picoseconds returns totalwaitingtime minimum waiting time measured in picoseconds examples minimumwaitingtime3 2 1 2 6 17 minimumwaitingtime3 2 1 4 minimumwaitingtime1 2 3 4 10 minimumwaitingtime5 5 5 5 30 minimumwaitingtime 0 this function takes a list of query times and returns the minimum waiting time for all queries to be completed args queries a list of queries measured in picoseconds returns total_waiting_time minimum waiting time measured in picoseconds examples minimum_waiting_time 3 2 1 2 6 17 minimum_waiting_time 3 2 1 4 minimum_waiting_time 1 2 3 4 10 minimum_waiting_time 5 5 5 5 30 minimum_waiting_time 0
def minimum_waiting_time(queries: list[int]) -> int:
    
    n = len(queries)
    if n in (0, 1):
        return 0
    return sum(query * (n - i - 1) for i, query in enumerate(sorted(queries)))


if __name__ == "__main__":
    import doctest

    doctest.testmod()