```java
class Solution {
public int numSubarrayProductLessThanK(int[] nums, int k) {
int n = nums.length;
int left = 0;
int right = 0;
int product = 1;
int result = 0;
while (right < n) {
product *= nums[right];
right++;
while (left < right && product >= k) {
product /= nums[left];
left++;
}
result += (right - left);
}
return result;
}
}
/**
T: O(n)
S: O(1)
prefix product idea
and sliding win
10, 5, 2, 6 (origin)
10 50 100 600 (product)
r
l
1 r - l = 1 ([10])
10, 5, 2, 6 (origin)
10 50 100 600
r
l
2 r - l = 2 ([5], [10,5])
10, 5, 2, 6 (origin)
10 50 100 600
r
l
r - l = 2 ([2], [5,2])
10, 5, 2, 6 (origin)
10 50 100 600
l r
r - l = 4 - 1 = 3 ([6], [2,6], [5,2,6])
1 + 2 + 2 + 3 = 8
*/
```