Ctrl K

Strong Runs of Fixed Length

Medium
A coach records an athlete's score for every practice in the array scores. They look at runs of exactly width consecutive practices and call a run strong if its average score is at least bar. Return the number of strong runs. Runs that start at different positions count separately, even if they overlap.
Example 1
scores=[3, 7, 4, 1, 8, 6], width=2, bar=5 → 3

The consecutive pairs are [3, 7] (average 5), [7, 4] (5.5), [4, 1] (2.5), [1, 8] (4.5) and [8, 6] (7). Three of them reach 5.

Example 2
scores=[2, 2, 2, 2], width=4, bar=3 → 0

The only window is the whole array, and its average 2 is below 3.

Example 3
scores=[10, 1, 10, 1, 10], width=3, bar=7 → 2
Constraints
  • 1 ≤ len(scores) ≤ 10⁵
  • 1 ≤ scores[i] ≤ 10⁴
  • 1 ≤ width ≤ len(scores)
  • 0 ≤ bar ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsShortest Stretch to the Goal MediumEvenly Stepped Stretches MediumLongest Run of Ones With One Fix MediumNearest k Values MediumWindows With a Small Product Medium
loading Python…
Input
scores=[3, 7, 4, 1, 8, 6], width=2, bar=5
Expected
3

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