You are given an integer array `nums` of n elements and an integer `k`. Find a contiguous subarray of length exactly `k` that has the maximum average value and return that average. Answers within $10^{-5}$ of the true value are accepted.
You are given an integer array nums of n elements and an integer k. Find a contiguous subarray of length exactly k that has the maximum average value and return that average. Answers within 10−5 of the true value are accepted.
Example 1:
Input: {"nums":[1,12,-5,-6,50,3],"k":4}
Output: 12.75
Constraints:
n==nums.length
1≤k≤n≤105
−104≤nums[i]≤104
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,12,-5,-6,50,3],"k":4}
The window has a fixed width of k = 4. Start by summing the first 4 numbers.