Skip to content

Instantly share code, notes, and snippets.

@riyafa
Created December 8, 2021 21:25
Show Gist options
  • Save riyafa/d9f12cfc816f3b646096ae63f8dc8e6a to your computer and use it in GitHub Desktop.
Save riyafa/d9f12cfc816f3b646096ae63f8dc8e6a to your computer and use it in GitHub Desktop.
class SubarrayProductLessThanK {
public int numSubarrayProductLessThanK(int[] nums, int k) {
if(k <= 1) {
return 0;
}
int count = 0;
int prod = 1;
for(int i =0, j =0; j < nums.length; j++) {
prod *= nums[j];
while(prod >= k) {
prod /= nums[i++];
}
count += j - i + 1;
}
return count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment