Finding frequency of each number .
for ( let i = 0 ; i < n ; i ++ ) { if ( hm . has ( arr [ i ] ) ) hm . set ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ; else hm . set ( arr [ i ] , 1 ) ; } let ans = 0 ;