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