Count the number of contiguous subarrays whose product is strictly less than a given threshold.
Given an array of positive integers and a positive integer , count how many contiguous subarrays have a product strictly smaller than .
A subarray must contain consecutive elements. You need to return the total number of such subarrays.
Input Format
- An integer array
numsof positive integers. - An integer
k.
You may assume the input is provided in the usual problem format for a coding platform.
Output Format
- Return a single integer: the number of contiguous subarrays whose product is strictly less than
k.
Constraints
1 <= nums.lengthnums[i] > 0k > 0
For practice purposes, the exact platform limits are not included here.
Example 1
Input
nums = [10, 5, 2, 6], k = 100
Output
8
Explanation
The valid subarrays are [10], [5], [2], [6], [10,5], [5,2], [2,6], and [5,2,6].
Example 2
Input
nums = [1, 2, 3], k = 0
Output
0
Explanation
No positive-product subarray can be strictly less than 0.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.