Skip to main content
LeetCode 1701, Medium. Topics: Array, Simulation. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 14 parametrized pytest cases, and a playground notebook:

Problem

There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrival<sub>i</sub>, time<sub>i</sub>]:
  • arrival<sub>i</sub> is the arrival time of the i<sup>th</sup> customer. The arrival times are sorted in non-decreasing order.
  • time<sub>i</sub> is the time needed to prepare the order of the i<sup>th</sup> customer.
When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input. Return the average waiting time of all customers. Solutions within 10-5 from the actual answer are considered accepted.

Examples

Constraints

  • 1 <= customers.length <= 10^5
  • 1 <= arrival<sub>i</sub>, time<sub>i</sub> <= 10^4
  • arrival<sub>i</sub> <= arrival<sub>i+1</sub>

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026