Question bank › Sliding Window
Dsa Sliding Window Easy

Finding Average in Sliding Window

You are given an array of integers and a positive integer k. Calculate the average of each contiguous subarray of size k. Input: The first line contains an integer n (1 ≤ n ≤ 10^5), the number of elements in the array. The second line contains n integers, which are the elements of the array. The third line contains an integer k (1 ≤ k ≤ n). Output: An array of floats representing the average of each contiguous subarray of size k. Example: Input: 4 1 3 2 4 2 Output: 2.0 3.0 3.0 (Explanation: The average values are calculated for the subarrays [1,3], [3,2], and [2,4].)

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