Problem · Array

Sliding Window Average (Meta Canada, E4/E5 :)

Learn this problem
EasyMeta logoMetaFULLTIMEPHONE SCREEN
See Meta hiring insights

Problem 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 >= 1
  • 1 <= windowSize <= nums.length
  • The result contains exactly nums.length - windowSize + 1 averages, one for each contiguous window.

More Meta problems

drafts saved locally
public double[] slidingWindowAverage(int[] nums, int windowSize) {
  // write your code here
}
nums[1, 2, 3, 4, 5, 6, 7, 8, 9]
windowSize7
expected[4.0, 5.0, 6.0]
checking account