Subarray Average of a Sequence
InterviewTime limit1sMemory limit256 MB
Count the contiguous subarrays of a given sequence whose elements have an average exactly equal to K.
- Level
Medium6 of 10
- Topics
- Prefix sum, Hash map, Array, Math
- Solved
- No attempts yet
Problem
A sequence of length is given. Count the number of intervals whose elements all have an average of exactly .
Input
The first line gives the size of the sequence and the desired average . (, )
The second line gives the sequence . (, )
Every number in the input is an integer.
Output
Print the number of intervals whose elements all have an average of .