Average Waiting Time
Real-world version: Average Wait at a Single PressThe statement here is our own: the same inputs, outputs and technique.
One press serves jobs in the order they arrive. customers[i] is a pair [arrival, minutes]: the minute the i-th job is handed in, and how long the press takes on it once started. Arrivals are given in non-decreasing order.
The press works on one job at a time, start to finish, and takes the next waiting job the moment it is free. If nothing is waiting, it idles until the next job arrives. A job's wait is the span from when it was handed in to when the press finishes it.
Return the average wait across all the jobs. An answer within 1e-5 of the true value is accepted.
Examples
Example 1
- Input
- customers = [[3, 7], [4, 2], [12, 5]]
- Output
- 6.666666666666667
The first job runs from minute 3 to 10, waiting 7. The second was handed in at 4 but starts at 10 and ends at 12, waiting 8. The press then idles until minute 12 and finishes the third at 17, waiting 5. The three waits average to 20 divided by 3.
Example 2
- Input
- customers = [[1, 10], [2, 1], [3, 1], [4, 1]]
- Output
- 10.0
One long job at the front holds up the three short ones behind it, which finish at minutes 12, 13 and 14.
Example 3
- Input
- customers = [[1, 1], [100, 1]]
- Output
- 1.0
The press is long since free when the second job arrives, so neither job waits for anything but its own minute on the press.
Constraints
- 1 <= customers.length <= 10^5
- customers[i].length == 2
- 1 <= customers[i][0] <= 10^4
- 1 <= customers[i][1] <= 10^4
- customers[i][0] <= customers[i + 1][0]
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def average_waiting_time(customers: list[list[int]]) -> float:public double averageWaitingTime(int[][] customers)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Concatenation of ArrayReal-world version: Two Cycle PlayoutEasy
- Reshape the MatrixReal-world version: Relaying the Contact SheetEasy
- Separate the Digits in an ArrayReal-world version: Digit Cells for the Ticket CodesEasy
- Distribute Elements Into Two Arrays IReal-world version: Splitting Parcels Onto Two Intake TraysEasy