Dsa
Arrays
Easy
Windowed Average
Given an array of integers and a window size, compute the average of all contiguous subarrays of that size. Each average should be rounded to two decimal places. The input format is as follows:
Input:
- The first line contains a single integer n (1 <= n <= 10^5) - the number of elements in the array.
- The second line contains n space-separated integers, the elements of the array.
- The third line contains a single integer k (1 <= k <= n) - the size of the sliding window.
Output:
- Print the averages of the sliding windows, space-separated, rounded to two decimal places.
Example:
Input:
5
1 3 2 5 7
3
Output:
2.00 3.33 4.67
Key concepts
arrayssliding windowaverages
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now