Count frequencies of all characters
let freq = new Array ( MAX_CHARS ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 } for ( let i = 0 ; i < n ; i ++ ) { freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; }