Ctrl K

Step Streak Score

Easy
A fitness app knows how many steps a person took each day: steps[i] is the count for day i. It rates every stretch of days consecutive days (all such stretches, which overlap) by the total number of steps T in it: - if T < low, the person loses 1 point; - if T > high, they gain 1 point; - otherwise the score stays the same. The score starts at 0. Return the final score; it may be negative.
Example 1
steps=[4, 9, 2, 8], days=2, low=10, high=12 → 1

Two-day windows: 4 + 9 = 13 > 12 gives +1, 9 + 2 = 11 is in range, and 2 + 8 = 10 is in range too (the bounds count). Total 1.

Example 2
steps=[1, 0, 3], days=1, low=2, high=5 → -2

Each day on its own: 1 and 0 are below 2 (−2), 3 is in range. Total −2.

Example 3
steps=[5, 5, 5], days=3, low=15, high=15 → 0
Constraints
  • 1 ≤ days ≤ len(steps) ≤ 10⁵
  • 0 ≤ steps[i] ≤ 20,000
  • 0 ≤ low ≤ high ≤ 2·10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsRepeat Within Reach EasyValues One Apart EasyBest Window Average EasyNeighbour Sums Around a Circle EasyTightest Group of Scores Easy
loading Python…
Input
steps=[4, 9, 2, 8], days=2, low=10, high=12
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 88 tests on the server, hidden ones included.