Programs

Find the average of all contiguous subarrays of fixed size in it

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)

Share This Post

Lost Password

Register

Do NOT follow this link or you will be banned from the site!