Dsa
Sliding Window
Easy
Daily Rainfall Analysis
Given an array of daily rainfall measurements, calculate the average rainfall over every consecutive 'k' days. Return an array containing the average rainfall for each 'k'-day segment, rounded to two decimal places.
Input:
- The first line contains two integers, n (the number of days) and k (the segment size).
- The second line contains n float numbers representing the rainfall measurements.
Output:
- Output a list of float numbers, each representing the average rainfall for each k-day segment.
Example:
Input:
5 3
2.5 3.5 4.0 5.0 6.0
Output:
3.67 4.50 5.50
Key concepts
sliding_windowarraysstatistics
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