All problems

Busy Jam Stretches

Easy · sliding window

Priya runs a jam stall at a weekend market. She writes down how many jars she sells each day, in order, in the list sales.

A stretch is k days in a row. A stretch is busy if the average number of jars sold per day over its k days is at least threshold.

Return how many busy stretches there are. Stretches that start on different days are counted separately, even if they have the same sales. If there are fewer than k days, there are no stretches, so return 0.

Examples

Example 1

Input: sales = [4, 6, 2, 9, 8, 1], k = 2, threshold = 5

Output: 3

The two-day totals are 10, 8, 11, 17 and 9. A busy stretch needs a total of at least 10, which three of them have.

Example 2

Input: sales = [3, 3, 3], k = 3, threshold = 4

Output: 0

The only stretch sells 9 jars, which is an average of 3, below 4.

Example 3

Input: sales = [7], k = 1, threshold = 7

Output: 1

Constraints