Traverse through array elements and count frequencies
for ( int i = 0 ; i < n ; ++ i ) { if ( mp1 . ContainsKey ( arr [ i ] ) ) { mp1 [ arr [ i ] ] = mp1 [ arr [ i ] ] + 1 ; } else { mp1 . Add ( arr [ i ] , 1 ) ; } }