people wait in line. Person takes time to be served. Minimize total waiting time (sum of all waiting times).
Example: times = [3, 2, 1]. If order is [3, 2, 1]: person waits , person waits , person waits + = . Total: + + = . If order is [1, 2, 3]: person waits , person waits , person waits + = . Total: + + = . Better!
What is the optimal order? Can you prove it? The order you choose affects everyone behind.