Count number of substrings with numeric value greater than X | Function that counts valid sub - strings ; Only take those numbers that do not start w$ith '0' . ; converting the sub - str$ing starting from index ' i ' and having length ' len ' to int and checking if it is greater than X or not ; Driver code
< ? php function countSubStr ( $ S , $ X ) { $ cnt = 0 ; $ N = strlen ( $ S ) ; for ( $ i = 0 ; $ i < $ N ; ++ $ i ) { if ( $ S [ $ i ] != '0' ) { for ( $ len = 1 ; ( $ i + $ len ) <= $ N ; ++ $ len ) { $ num = intval ( substr ( $ S , $ i , $ len ) ) ; if ( $ num > $ X ) $ cnt ++ ; } } } return $ cnt ; } $ S = "2222" ; $ X = 97 ; echo countSubStr ( $ S , $ X ) ; ? >