Stretches Between Two Bounds
Return how many stretches of nums (one or more items next to each other) have low as their smallest item and high as their largest item. Stretches at different positions count separately.
Example 1
nums [2,4,2,5,4]
low 2
high 4
returns 3
The stretches are [2, 4], [2, 4, 2] and [4, 2]. Any stretch that holds the 5 has a largest item above 4.
Example 2
nums [3,3,3]
low 3
high 3
returns 6
With both bounds 3, every one of the six stretches fits.
Constraints
1 <= len(nums) <= 300-106 <= nums[i] <= 106-106 <= low <= high <= 106
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Two pointers problems
- Busy WindowsBeginner
- Change Over k DaysBeginner
- Common StartBeginner
- Fixes to Make a MirrorBeginner
- Flip a StretchBeginner
- Fold and AddBeginner
- Lighten the ShelfBeginner
- Peel Matching EndsBeginner