2
* @param {number[][]} customers5
var averageWaitingTime = function (customers) {6
let n = customers.length;7
let starts = Array(n).fill(0);8
// the first customer do not have to wait for the prev customer so his start time == arrival time9
starts[0] = customers[0][0];10
let totalWait = customers[0][1];11
for (let i = 1; i < n; i++) {12
// The start of the current customer is the max of (start + time of prev customer) or the arrival time of existing customer13
starts[i] = Math.max(starts[i - 1] + customers[i - 1][1], customers[i][0]);14
totalWait += starts[i] - customers[i][0] + customers[i][1];