Problem statement
You are given an array and a number k. Report the average of every group of k neighbouring values, in the order the groups appear.
The answer holds one entry per group, so it has n - k + 1 values. When the array is shorter than k there is no group and the answer is an empty list.
Examples
Inputnums = [2, 1, 5, 1, 3, 2], k = 3
Output[2.67, 2.33, 3.00, 2.00]
Each average is that group's total divided by 3.
Inputnums = [1, 2], k = 4
Output[]
No group of four fits, so there is no average to report.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing