#K66447. Subarray Product Less Than K
Subarray Product Less Than K
Subarray Product Less Than K
Given an array of positive integers and an integer (k), your task is to determine the number of contiguous subarrays (subsegments) for which the product of all elements is less than (k). A contiguous subarray is a sequence of consecutive elements from the array. Formally, for a subarray with indices (l) to (r), the condition is: [ \prod_{i=l}^{r} a_i < k ]
You are expected to provide an efficient solution possibly employing a sliding window technique.
inputFormat
The input is given in two lines. The first line contains two integers (n) and (k), where (n) is the number of elements in the array and (k) is the threshold. The second line contains (n) space-separated positive integers representing the array elements.
outputFormat
Output a single integer representing the number of contiguous subarrays whose product is strictly less than (k).## sample
4 100
10 5 2 6
8