Iterate over every element in the array and increase the frequency of the element in hash map
for ( let i = 0 ; i < n ; ++ i ) { if ( freq . has ( arr [ i ] ) ) { freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; } else { freq . set ( arr [ i ] , 1 ) ; } } let res = 0 ;