Given an array with positive and negative numbers, find the maximum average subarray which length should be greater or equal to given length k.
Note
It’s guaranteed that the size of the array is greater or equal to k.
Example
No.1
Input:
[1,12,-5,-6,50,3]
3
Output:
15.667
Explanation:
(-6 + 50 + 3) / 3 = 15.667
No.2
Input:
[5]
1
Output:
5.000
Code
1 | // (nums[i] + nums[i+1] + … + nums[j]) / (j-i+1) >= x |