In - place remove non - repeating characters from the string
let k = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( freq [ str [ i ] . charCodeAt ( 0 ) ] > 1 ) str . replace ( str [ k ++ ] , str [ i ] ) ; str . replace ( str [ k ] , ' \0 ' ) ;