Untitled
unknown
plain_text
a year ago
738 B
4
Indexable
/********************************************************************** JAVA *****************************************************************/
// Approach: Standard Sliding Window Problem
// T.C: O(N)
// S.C: O(1)
public class Solution {
public int numSubarrayProductLessThanK(int[] nums, int k) {
if (k <= 1)
return 0;
int n = nums.length;
int count = 0;
int i = 0;
int j = 0;
int prod = 1;
while (j < n) {
prod *= nums[j];
while (prod >= k) {
prod /= nums[i];
i++;
}
count += (j - i) + 1;
j++;
}
return count;
}
}
Editor is loading...
Leave a Comment