Loading content...
You are provided with an integer array nums containing n elements and a positive integer k representing the window size.
Your task is to identify a contiguous subarray (also known as a window) of exactly k consecutive elements that yields the highest arithmetic mean among all possible windows of that size.
Return the maximum average value as a floating-point number.
Key Concepts:
Note: Any answer within 10⁻⁵ of the actual result will be considered correct due to floating-point precision considerations.
nums = [1,12,-5,-6,50,3]
k = 412.75000The possible windows of size 4 are:
The window [12,-5,-6,50] has the maximum average of (12 + (-5) + (-6) + 50) / 4 = 51 / 4 = 12.75.
nums = [5]
k = 15.00000There is only one element and one possible window of size 1. The average is simply 5 / 1 = 5.0.
nums = [0,1,2,3,4,5]
k = 34.00000The possible windows of size 3 are:
The last window [3,4,5] yields the maximum average of 4.0.
Constraints