Skip to content

Maximum Average Subarray I

EasySliding Window
Decode it first. Clues, constraints, pattern and plan before any code.

You get an integer array nums and a length k. Look at every contiguous subarray of length exactly k and return the highest average among them.

nums = [1, 12, -5, -6, 50, 3], k = 4   →  12.75   ((12 - 5 - 6 + 50) / 4)
nums = [5], k = 1                      →  5.0

Answers within 10^-5 of the true value are accepted.

Constraints

  • 1 <= k <= nums.length <= 10^5
  • -10^4 <= nums[i] <= 10^4