Problem · Array
Fixed-Window Rolling Mean
Learn this problemProblem statement
Given an integer array nums and a positive windowSize, return the arithmetic mean of every complete contiguous window of that size, from left to right.
Update the running window in constant time as it advances.
Function
fixedWindowRollingMean(nums: int[], windowSize: int) → double[]Examples
Example 1
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]windowSize = 7return = [4.0, 5.0, 6.0]The three complete windows have sums 28, 35, and 42; dividing each by 7 gives the returned means.
Constraints
nums.length >= 11 <= windowSize <= nums.length- The result contains exactly
nums.length - windowSize + 1averages, one for each contiguous window.