Moving Average

MediumStatisticsSliding WindowArray

Description

Given an array nums and a window size k (1 ≤ k ≤ nums.length), return the array of averages of every contiguous window of size k, each rounded to 4 decimal places.

Examples

Input:nums = [1,2,3,4,5], k = 2
Output:[1.5,2.5,3.5,4.5]
Explanation:

Averaging each window of 2 consecutive values produces [1.5,2.5,3.5,4.5].

Input:nums = [10,20,30], k = 3
Output:[20]
Explanation:

Averaging each window of 3 consecutive values produces [20].

Input:nums = [4,8,6,2], k = 2
Output:[6,7,4]
Explanation:

Averaging each window of 2 consecutive values produces [6,7,4].

Constraints

  • 1 ≤ k ≤ nums.length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.