Dsa
Greedy
Warm-up
Airport Charging
There is only one power outlet at an airport gate, and N travelers are waiting to charge their phones. Each traveler i needs the outlet for T_i minutes. A traveler's 'waiting time' is defined as the total time from the start until they finish charging their phone. You want to arrange the order of travelers to minimize the sum of all travelers' waiting times.
Input Format:
A single line of space-separated integers representing the charging durations needed by each traveler.
Output Format:
Print the minimum possible sum of all waiting times.
Example:
Input:
5 10 2
Output:
26
(Explanation: If the order is 2, 5, 10: Traveler 1 finishes at 2, Traveler 2 finishes at 2+5=7, Traveler 3 finishes at 7+10=17. Sum = 2+7+17 = 26.)
Key concepts
sortinggreedy
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now