Store frequencies of array elements
let frequency = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( frequency . has ( arr [ i ] ) ) { frequency . set ( arr [ i ] , frequency . get ( arr [ i ] ) + 1 ) ; } else { frequency . set ( arr [ i ] , 1 ) ; } } let count = 0 ;