Sub | Function that checks if the string contain exactly K characters having ASCII value greater than p ; if ASCII value is greater than ' p ' ; if count of satisfying characters is equal to ' K ' then return true ; otherwise return false ; function to count sub - strings ; length of the string ; count of sub - strings ; ' i ' is the starting index for the sub - string ; ' j ' is the no . of characters to include in the sub - string ; check if the sub - string satisfies the condition ; Driver code
function isValidSubString ( r , K , p ) { var c = 0 ; for ( var i = 0 ; i < r . length ; i ++ ) { if ( r . charCodeAt ( i ) > p ) c ++ ; } if ( c == K ) return true ; else return false ; } function countSubStrings ( s , K , p ) { var l = s . length ; var count = 0 ; for ( var i = 0 ; i < l ; i ++ ) { for ( var j = K ; ( i + j ) <= l ; j ++ ) { var r = s . substring ( i , i + j ) ; if ( isValidSubString ( r , K , p ) ) count ++ ; } } document . write ( count + " " ) ; } var s = " " ; var K = 4 ; var p = 110 ; countSubStrings ( s , K , p ) ;