Minimum removals required to make frequency of all remaining array elements equal | C # program for the above approach ; Function to count the minimum removals required to make frequency of all array elements equal ; Stores frequency of all array elements ; Traverse the array ; Stores all the frequencies ; Traverse the map ; Sort the frequencies ; Count of frequencies ; Stores the final count ; Traverse the vector ; Count the number of removals for each frequency and update the minimum removals required ; Print the final count ; Driver Code ; Given array ; Size of the array ; Function call to print the minimum number of removals required
using System ; using System . Collections . Generic ; class GFG { static void minDeletions ( int [ ] arr , int N ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( freq . ContainsKey ( arr [ i ] ) ) freq [ arr [ i ] ] ++ ; else freq [ arr [ i ] ] = 1 ; } List < int > v = new List < int > ( ) ; foreach ( var z in freq ) { v . Add ( z . Value ) ; } int sz = v . Count ; int [ ] temp = new int [ sz ] ; for ( int i = 0 ; i < v . Count ; i ++ ) temp [ i ] = v [ i ] ; Array . Sort ( temp ) ; for ( int i = 0 ; i < v . Count ; i ++ ) v [ i ] = temp [ i ] ; int size = v . Count ; int ans = N - ( v [ 0 ] * size ) ; for ( int i = 1 ; i < v . Count ; i ++ ) { if ( v [ i ] != v [ i - 1 ] ) { int safe = v [ i ] * ( size - i ) ; ans = Math . Min ( ans , N - safe ) ; } } Console . WriteLine ( ans ) ; } public static void Main ( ) { int [ ] arr = { 2 , 4 , 3 , 2 , 5 , 3 } ; int N = arr . Length ; minDeletions ( arr , N ) ; } }