Number of subarrays having product less than K | PHP program to count subarrays having product less than k . ; Counter for single element ; Multiple subarray ; If this multiple is less than k , then increment ; Driver Code
< ? php function countsubarray ( $ array , $ n , $ k ) { $ count = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ array [ $ i ] < $ k ) $ count ++ ; $ mul = $ array [ $ i ] ; for ( $ j = $ i + 1 ; $ j < $ n ; $ j ++ ) { $ mul = $ mul * $ array [ $ j ] ; if ( $ mul < $ k ) $ count ++ ; else break ; } } return $ count ; } $ array = array ( 1 , 2 , 3 , 4 ) ; $ k = 10 ; $ size = sizeof ( $ array ) ; $ count = countsubarray ( $ array , $ size , $ k ) ; echo ( $ count . " " ) ; ? >