Index in [ ] freq to segregate the string
var pos = Q [ 0 ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; for ( var i = 0 ; i <= pos ; i ++ ) { while ( freq [ i ] > 0 ) { var c = String . fromCharCode ( " " . charCodeAt ( 0 ) + i ) ; sb += c ; freq [ i ] -- ; } }