Remove elements from the array which appear more than k times | C # program to remove the elements which appear more than k times from the array . ; Hash map which will store the frequency of the elements of the array . ; Incrementing the frequency of the element by 1. ; Print the element which appear less than or equal to k times . ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void RemoveElements ( int [ ] arr , int n , int k ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( mp . ContainsKey ( arr [ i ] ) ) mp [ arr [ i ] ] ++ ; else mp [ arr [ i ] ] = 1 ; } for ( int i = 0 ; i < n ; ++ i ) { if ( mp . ContainsKey ( arr [ i ] ) && mp [ arr [ i ] ] <= k ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } } static public void Main ( ) { int [ ] arr = { 1 , 2 , 2 , 3 , 2 , 3 , 4 } ; int n = arr . Length ; int k = 2 ; RemoveElements ( arr , n , k ) ; } }