FunctionRacerProblemsRace

Subarrays With Small Product

MediumTwo pointersPython, JavaScript, TypeScript, Java, C++

All items of nums are positive. Count the contiguous, non-empty stretches whose items multiply to a number strictly less than k.

Example 1

nums [10,5,2,6]
k 100
returns 8

8 stretches, e.g. [10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6].

Example 2

nums [1,2,3]
k 0
returns 0

No product can be below 0.

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