Dsa
Prefix Sum
Easy
Perfect Average Intervals
A student records their daily study scores. Given an array of N scores and a target average K, find the total number of contiguous time intervals (subarrays) where the average score is exactly K.
Example:
Input:
5 10
10 12 8 10 10
Output:
6
Explanation:
Target average is 10. The intervals with average 10 are: [10] (idx 0), [12, 8], [10] (idx 3), [10] (idx 4), [10, 12, 8], [10, 10] (idx 3-4). Total 6.
Key concepts
prefix_sumhashmap
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