Every time any new element is added to the sub array then there are possibilities either the product of the elements will be less than k or greater than equal to k.

Start with first element and keep adding elements till the product of elements are less than K.

Once the product is greater than k than, start dividing the product with elements of sub array, from the start index of that particular sub array.

Repeat the above 2 steps till we navigate the entire array.

Now let’s discuss how will count the sub arrays.

If product of all the elements in array is less than K that means all the subarrays will also have product less than K.

Let’s say we have 3 elements in the subarray where product is less than k and after adding the 4th element in subarray, product is still less then we will have 3 more subarrays(same as the previous size of array) in our result see the explanation below

[1, 2, 3], K = 40. Add another element 4 so new window with product less than 40 is [1, 2, 3, 4]. So all the new subarrays with product less than 40 will be – {1, 2, 3, 4}, {2, 3, 4}, {3, 4}, {4}.

Let’s take one Example, have 2 pointers start and end to track the sliding window