FunctionRacerProblemsRace

Stretches Between Two Bounds

HardTwo pointersPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems