57. The Best Average in a Window
Easy
Given the array nums and an integer k, consider every contiguous segment of nums containing exactly k elements. Return the greatest arithmetic mean among these segments as a number.
Example 1
Input: nums = [4, 2, 10, 3, 8], k = 2
Output: 6.5
Explanation: The segment [10, 3] has the greatest average: 6.5.
Example 2
Input: nums = [-5, -2, -3], k = 1
Output: -2
Explanation: For segments of size 1, the greatest average is the largest element.
Constraints
- 1 <= nums.length <= 100000
- -10000 <= nums[i] <= 10000
- 1 <= k <= nums.length
Sliding windowArrays
Saved in this browser
Caso 1
nums =
[4,2,10,3,8]
k =
2
Expected =
6.5
Caso 2
nums =
[-5,-2,-3]
k =
1
Expected =
-2
Run checks these 2 cases. Submit runs all 10, including hidden ones.