Number of substrings of one string present in other | javascript program to count number of substrings of s1 present in s2 . ; s3 stores all substrings of s1 ; check the presence of s3 in s2 ; Driver code
function countSubstrs ( s1 , s2 ) { var ans = 0 ; for ( var i = 0 ; i < s1 . length ; i ++ ) { var s3 = " " ; var s4 = s1 ; for ( var j = i ; j < s1 . length ; j ++ ) { s3 += s4 [ j ] ; if ( s2 . indexOf ( s3 ) != - 1 ) ans ++ ; } } return ans ; } var s1 = " " , s2 = " " ; document . write ( countSubstrs ( s1 , s2 ) ) ;