Skip to content

Latest commit

 

History

History
67 lines (51 loc) · 1.59 KB

_1701. Average Waiting Time.md

File metadata and controls

67 lines (51 loc) · 1.59 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 09, 2024

Last updated : July 09, 2024


Related Topics : Array, Simulation

Acceptance Rate : 73.05 %


Solutions

Python

class Solution:
    def averageWaitingTime(self, customers: List[List[int]]) -> float:
        output = 0
        currentTime = customers[0][0]
        custCount = len(customers)

        for i, customer in enumerate(customers) :
            if customer[0] > currentTime :
                currentTime = customer[0]
            output += (currentTime + customer[1]) - customer[0]
            currentTime += customer[1]
            
        return output / custCount

JavaScript

/**
 * @param {number[][]} customers
 * @return {number}
 */
var averageWaitingTime = function(customers) {
    var output = 0;
    var currentTime = 0;

    function cust(customer) {
        if (customer[0] > currentTime) {
            currentTime = customer[0];
        }

        output += (currentTime + customer[1]) - customer[0];
        currentTime += customer[1];
    }

    customers.forEach(cust);
    return output / customers.length;
};