Your question is Sliding Window Moving Average. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Arista EOS telemetry can produce a sequence of numeric samples such as interface utilization or packet rates. Given the samples and a fixed window size, return the average for every contiguous window of that size.
Implement moving_average(nums, k) using a sliding window. Each output value must equal the arithmetic mean of one window, starting with nums[0:k] and advancing one position at a time.
nums, a non-empty list of integers or floating-point numbers, and k, a positive integer window size.len(nums) - k + 1.def moving_average(nums, k):