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 :)
Examples
01 · Example 1
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] windowSize = 7 return = [4.0, 5.0, 6.0]
KEEP SMILING :))
More Meta problems
- Merge Three Sorted ArraysPHONE SCREEN · Seen May 2026
- Diagonal Traverse (for E4 ;)PHONE SCREEN · Seen Mar 2025
- Find Peak ElementPHONE SCREEN · Seen Mar 2025
- Find Pair Closest to K (for E5 :)PHONE SCREEN · Seen Feb 2025
- Get Minimum Round Trip Cost (: for E4 && E5 :)PHONE SCREEN · Seen Feb 2025
- Max Consecutive Ones III (for E5 :)PHONE SCREEN · Seen Feb 2025
- Nested List Weight Sum (for E4)PHONE SCREEN · Seen Feb 2025
- Build Blocks and Obstacles on a Number LineSeen Oct 2024
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]
sign in to submit