Traverse given string again and print all those characters whose frequency is more than or equal to k .
for ( let i = 0 ; i < n ; i ++ ) { if ( freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] >= k ) { document . write ( str [ i ] ) ; } } }