Minimum number of distinct elements after removing m items | C # program for Minimum number of distinct elements after removing m items ; Function to find distintc id 's ; Store the occurrence of ids ; Start removing elements from the beginning ; Remove if current value is less than or equal to mi ; Return the remaining size ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int distinctIds ( int [ ] arr , int n , int mi ) { Dictionary < int , int > m = new Dictionary < int , int > ( ) ; int count = 0 ; int size = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . ContainsKey ( arr [ i ] ) == false ) { m [ arr [ i ] ] = 1 ; size ++ ; } else { m [ arr [ i ] ] ++ ; } } foreach ( KeyValuePair < int , int > mp in m ) { if ( mp . Key <= mi ) { mi -= mp . Key ; count ++ ; } } return size - count ; } static void Main ( ) { int [ ] arr = { 2 , 3 , 1 , 2 , 3 , 3 } ; int m = 3 ; Console . WriteLine ( distinctIds ( arr , arr . Length , m ) ) ; } }