### Count and print all Subarrays with product less than K in O(n)

**Problem:**. Write an algorithm to count all the possible sub arrays where product of all the elements in the sub array is less than k. You are given with an interger array and a value ‘k’.

Example:

Int [] nums = {5, 3, 2, 4}; K = 100 Output: 11 Sub arrays: [5], [5 3], [5, 3, 2], [3], [5, 2], [5, 4, 3], [2], [2, 4], [4], [4, 2, 3], [5, 2, 4] Approach:Using nested loops. 1:Calculate the possible subarrays. Run the outer loop that will decide the starting point to array_size(i.e 'i' loop) Now, run the first inner loop will run from starting point to array_size.(i.e 'j' loop) Run the second inner loop from initial to 'j'.(i.e 'k' loop) Find out which array has elements has product less than k. Time complexity: O(n^3) Code: Run Code

CommentsNo comment yet.