04. Count the subarrays having product less than k
My Approach
Example
n = 6, k = 10
a = {1, 2, 3, 4, 3 , 2}
dry run - (every value represents loop)
{1, 2, 3, 4, 3 , 2} => currProd = 1, out = 0 + 1 = 1
-
{1, 2, 3, 4, 3 , 2} => currProd = 2, out = 1 + 2 = 3
- -
{1, 2, 3, 4, 3 , 2} => currProd = 6, out = 3 + 3 = 6
- - -
{1, 2, 3, 4, 3 , 2} => currProd = 24
- - - -
at this starting pointer updates
{1, 2, 3, 4, 3 , 2} => currProd = 4, out = 6 + 1 = 7
-
{1, 2, 3, 4, 3 , 2} => currProd = 12
- -
at this starting pointer updates
{1, 2, 3, 4, 3 , 2} => currProd = 3, out = 7 + 1 = 8
-
{1, 2, 3, 4, 3 , 2} => currProd = 6, out = 8 + 2 = 10
- -Time and Auxiliary Space Complexity
Code (C++)
Contribution and Support
Last updated