Leet Code Daily 2024-07-09 - Average Waiting Time
Code
class Solution {
public:
double averageWaitingTime(vector<vector<int>>& customers) {
double total_wait_time = 0;
int last_idle_time = INT_MIN;
for (const auto& customer : customers) {
last_idle_time = max(last_idle_time, customer[0]) + customer[1];
total_wait_time += last_idle_time - customer[0];
}
return total_wait_time / customers.size();
}
};