find the number of possible contiguous subarrays having product less than a given number K. - Codeprg

Breaking

programing News Travel Computer Engineering Science Blogging Earning

Thursday 11 July 2019

find the number of possible contiguous subarrays having product less than a given number K.

Given an array of positive numbers, the task is to find the number of possible contiguous subarrays having product less than a given number K.
Example:
Input:
2
4 10
1 2 3 4
7 100
1 9 2 8 6 4 3

Output:
7
16

Input : A[]={1, 2,3,4} 
        K = 10
Output : 7
The contiguous subarrays are {1}, {2}, {3}, {4}
{1, 2}, {1, 2, 3} and {2, 3} whose count is 7.