Busy Windows
visits[i] is the number of visitors a shop had in hour i. A window is a block of exactly k hours in a row, and a window is busy when its visitors add up to limit or more.
Return how many busy windows there are. Windows may overlap. If k is larger than the number of hours, there is no window at all, so return 0.
Example 1
visits [3,1,4,1,5]
k 2
limit 5
returns 3
The windows of 2 hours add up to 4, 5, 5 and 6. Three of them reach 5.
Example 2
visits [2,2,2]
k 3
limit 6
returns 1
The only window is the whole list: 2 + 2 + 2 = 6, which reaches the limit exactly.
Example 3
visits [9,9]
k 3
limit 1
returns 0
Two hours cannot hold a window of 3.
Constraints
0 <= len(visits) <= 300 <= visits[i] <= 501 <= k <= 300 <= limit <= 1500
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Two pointers problems
- Change Over k DaysBeginner
- Common StartBeginner
- Fixes to Make a MirrorBeginner
- Flip a StretchBeginner
- Fold and AddBeginner
- Lighten the ShelfBeginner
- Peel Matching EndsBeginner
- Sums of Every WindowBeginner