Maximum Average Subarray I
Easy
LC #643
arrayfixed windowNot attempted yet
Given an integer list nums and an integer k, look
at every block of exactly k consecutive numbers.
Return the largest average among those blocks, as a
float.
Example 1
Input: nums = [1,12,-5,-6,50,3], k = 4
Output: 12.75
[12,-5,-6,50] sums to 51; 51 / 4 = 12.75.
Example 2
Input: nums = [5], k = 1
Output: 5.0
Example 3
Input: nums = [0,4,0,3,2], k = 1
Output: 4.0
Constraints
- 1 ≤ k ≤ len(nums) ≤ 10^5
- -10^5 ≤ nums[i] ≤ 10^5
- Answers within 10^-5 are accepted.