Average Waiting Time

MediumMatrix

Description

Given an matrix customers, a chef prepares orders one at a time. Given arrival times and preparation times, return the average waiting time.

Examples

Input:customers = [[1,2],[2,5],[4,3]]
Output:1.67
Explanation:

Customer 1 arrives at t=1, chef starts immediately, finishes at t=3 (=2). Customer 2 arrives at t=2, chef busy until t=3, finishes at t=9 (=7). Customer 3 arrives at t=4, chef busy until t=9, finishes at t=12 (=8). Average = (2+7+8)/3 = 5.67.

Input:customers = [[3,1],[6,2],[8,1]]
Output:0.0
Explanation:

Customer 1 arrives at t=3, finishes at t=4 (=1). Customer 2 arrives at t=6, finishes at t=8 (=2). Customer 3 arrives at t=7, chef busy until t=8, finishes at t=9 (=2). Average = (1+2+2)/3 = 1.67.

Input:customers = [[0,3]]
Output:0.0
Explanation:

A single customer arrives at time 0, preparation takes 3 minutes, finishes at t=3. ing time is 3-0=3. Average is 3.0.

Constraints

  • 1 ≤ customers.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!