Counting freq of each element
if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1 ; } else { mp . Add ( arr [ i ] , 1 ) ; } } int ans = 0 ; foreach ( KeyValuePair < int , int > x in mp ) { int value = x . Key ; int freq = x . Value ;