Dsa
Sliding Window
Warm-up
Window Size Average
Given an array of integers and a window size k, calculate the average of each window as it slides across the array and print the averages rounded to two decimal places.
Input format:
- The first line contains an integer n (1 <= n <= 10^5).
- The second line contains n space-separated integers, the elements of the array (each element ai (−10^4 <= ai <= 10^4)).
- The third line contains an integer k (1 <= k <= n).
Output format:
- Print n-k+1 space-separated averages rounded to two decimal places.
Example:
Input:
5
1 2 3 4 5
3
Output:
2.00 3.00 4.00
Key concepts
sliding_windowarraysaverages
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