Question bank › Sliding Window
Dsa Sliding Window Warm-up

Average of All Subarrays of Size K

You need to compute the average of all contiguous subarrays of size `k` in an array of integers `arr`. Input Format: - The first line contains space-separated integers representing the array `arr` (1 <= |arr| <= 10000, -1000 <= arr[i] <= 1000). - The second line contains the integer `k` (1 <= k <= |arr|). Output Format: - Print a space-separated float representing the averages of each subarray of size `k`, rounded to two decimal places. Example: Input: 1 2 3 4 5 3 Output: 2.00 3.00 4.00 (These are the averages of the subarrays [1,2,3], [2,3,4], [3,4,5].)

Key concepts

sliding_windowarraysaveraging

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.