Python interview question: maximum average subarray of at least k
Problem
orders[i] is the number of orders in hour i. For a press release, return the highest average number of orders per hour over any run of at least k consecutive hours.
def best_period_average(orders: list[int], k: int) -> float:
Example
orders = [6, 2, 9, 9, 2, 9, 9, 3], k = 3 → 7.6indices 2–6, five hours; the best run of exactly 3 gives only 7
Solve it free
Checked against hidden tests, right in your browser. No sign-up needed.