Problem · Array
Sliding Window Average (Meta Canada, E4/E5 :)
Learn this problemProblem statement
Given an integer array as input and a window size, find the sliding window average.
Follow up: Design an API to return the sliding average, if input is given as a stream instead. Moving Average from Data Stream (This seems to be a LC question :)
Function
slidingWindowAverage(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]KEEP SMILING :))
Constraints
nums.length >= 11 <= windowSize <= nums.length- The result contains exactly
nums.length - windowSize + 1averages, one for each contiguous window.