Subarrays With Small Product
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
1 <= len(nums) <= 301 <= nums[i] <= 200 <= k <= 200
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.