Finding frequency of each number .
for ( int i = 0 ; i < n ; i ++ ) { if ( hm . ContainsKey ( arr [ i ] ) ) { int a = hm [ arr [ i ] ] ; hm . Remove ( arr [ i ] ) ; hm . Add ( arr [ i ] , a + 1 ) ; } else hm . Add ( arr [ i ] , 1 ) ; } int ans = 0 ;