Maximum Average Subarray I — Sliding Window
Given whole numbers and a block length, report the highest average any run of that many neighbouring values reaches.
Sliding Window · Easy
The problem
Given integers and a length k, find the run of k neighbours with the highest average, and give that average.
What to return
- Return the highest average over any run of k consecutive numbers.
- An answer within 1e-5 of the true value is accepted.
- Large hidden tests (up to 400 numbers) run under a step budget of executed lines.
Constraints
- 1 ≤ k ≤ len(nums) ≤ 400
- −10⁴ ≤ nums[i] ≤ 10⁴
- Your code may run at most 2,420 counted steps on the largest case.
Example
- Input
nums = [1, 12, -5, -6, 50, 3], k = 4- Output
12.75