Delete all odd frequency elements from an Array | C # program to removes all odd frequency elements from an Array ; Function that removes the elements which have odd frequencies in the array ; Create a map to store the frequency of each element ; Remove the elements which have odd frequencies ; If the element has odd frequency then skip ; Driver code ; Function call
using System ; using System . Collections . Generic ; class GFG { static void remove ( int [ ] arr , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1 ; } else { mp . Add ( arr [ i ] , 1 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( ( mp . ContainsKey ( arr [ i ] ) && mp [ arr [ i ] ] % 2 == 1 ) ) continue ; Console . Write ( arr [ i ] + " , ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 3 , 3 , 2 , 2 , 4 , 7 , 7 } ; int n = arr . Length ; remove ( arr , n ) ; } }