Description
Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements is strictly less than k.
Examples
Input:
nums = [10,5,2,6], k = 100Output:
8Explanation:
8 subarrays have product < 100.
Input:
nums = [1,2,3], k = 0Output:
0Explanation:
Since k = 0 and all numbers are positive, no subarray can have a product strictly less than 0. All possible products will be positive integers ≥ 1.
Input:
nums = [1,1,1], k = 2Output:
6Explanation:
All subarrays have product = 1, which is < 2. The 6 valid subarrays are: [1], [1], [1], [1,1], [1,1], and [1,1,1]. This demonstrates how arrays with small values can produce many valid subarrays.
Constraints
- •
1 ≤ nums.length ≤ 3 * 10^4 - •
1 ≤ nums[i] ≤ 1000