iterate and mark the frequencies of all characters in str1
for ( let i = 0 ; i < l1 ; i ++ ) { freq [ str1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; } let l2 = str2 . length ; for ( let i = 0 ; i < l2 ; i ++ ) { freq2 [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; } let count = Number . MAX_VALUE ;