Count of Substrings that can be formed without using the given list of Characters | Function to find the Number of sub - Strings without using given character ; Mark the given characters in the freq array ; Count variable to store the count of the characters until a character from given L is encountered ; If a character from L is encountered , then the answer variable is incremented by the value obtained by using the mentioned formula and count is set to 0 ; For last remaining characters ; Driver code
function countSubString ( S , L , n ) { var freq = new Array ( 26 ) . fill ( 0 ) ; var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { freq [ L [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = 1 ; } var count = 0 ; for ( const x of S ) { if ( freq [ x . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] > 0 ) { ans = ans + parseInt ( ( count * count + count ) / 2 ) ; count = 0 ; } else count ++ ; } ans += parseInt ( ( count * count + count ) / 2 ) ; return ans ; } var S = " " ; var L = [ " " , " " , " " ] ; var n = L . length ; document . write ( countSubString ( S . split ( " " ) , L , n ) ) ;