Count the number of removals for each frequency and update the minimum removals required
if ( v . get ( i ) != v . get ( i - 1 ) ) { int safe = v . get ( i ) * ( size - i ) ; ans = Math . min ( ans , N - safe ) ; } }