Loop to count the occurrence of ith character before jth character in the given String
for ( var i = 0 ; i < n ; i ++ ) { var c = ( s . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ) ; for ( var j = 0 ; j < 26 ; j ++ ) dp [ j ] += freq [ j ] ;