Trains the technique from
LeetCode 930Binary Subarrays With SumThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A foot pedal on a press writes one entry per minute into a log. minutes[i] is 1 if the pedal was pressed during minute i and 0 if it was not.
A stretch is any run of one or more consecutive minutes from the log. Count the stretches that contain exactly goal presses. Two stretches are different when they start or end at different minutes, even when they hold the same entries.
Return that count.
Example 1
Writing a stretch as the minutes it covers, the qualifying ones are minutes 0-1, minutes 0-2 and minutes 1-3. Each of those holds two presses.
Example 2
Six stretches hold only the press at minute 1: they start at minute 0 or 1 and end at minute 1, 2 or 3. Three more hold only the press at minute 4: they start at minute 2, 3 or 4 and end at minute 4.
Example 3
The log has no presses at all, so every stretch qualifies: three of length one, two of length two and one of length three.
Example 4
The only stretch with no press is the single minute 1.
Example 5
The one available stretch holds a press, so nothing qualifies.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def count_stretches(minutes: list[int], goal: int) -> int:public int countStretches(int[] minutes, int goal)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.