Given an array, find the average of all contiguous subarrays of size ‘n’ in it.
Array: [1, 3, 2, 6, -1, 4, 1, 8, 2], n=5
Output: [2.2, 2.8, 2.4, 3.6, 2.8]
Solution:
Sliding Window algorithm can be used to resolve this.
Time Complexity:
O(n)
Space Complexity:
O(1)