35: Maximum average subarray
Given an array of integers
, find the contiguous subarray of length k
which has the largest average sum
, return its average sum
Example 1
Input: array = [-4, 1, 2, -3, 1], k = 2
Output: 1.5
Explanation:
[1, 2]
is the subarray with the largest average sum1.5
Example 2
Input: [1, 1, 2, 5], k = 2
Output: 3.5