Skip to the code
cf.
+10 XP

#126 Count Steady Sales Weeks

easy

A shop dashboard marks a stretch of k days in a row as steady when the average daily sales over those days is at least threshold.

Write countSteady(sales, k, threshold) that returns how many stretches of exactly k consecutive days are steady. Stretches may overlap.

Example 1

Input: sales = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3

The stretches [2, 5, 5], [5, 5, 5], and [5, 5, 8] average 4, 5, and 6.

Example 2

Input: sales = [1,1,1], k = 1, threshold = 2
Output: 0

No single day reaches 2.

Constraints

  • 1 <= k <= sales.length <= 100000
  • 0 <= sales[i], threshold <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).