Map M will store the frequency of each element in the array
Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int x = 0 ; x < n ; x ++ ) { if ( mp . ContainsKey ( arr [ x ] ) ) { mp [ arr [ x ] ] ++ ; } else { mp [ arr [ x ] ] = 1 ; } }