Here we don 't need to fix K  consecutive element criteria.
let temp = frequency_array [ i ] ; frequency_array [ i ] -= temp ; let st = String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; while ( temp > 0 ) { ans += st ; temp -- ; } }