Map M will store the frequency of each element in the array
var mp = new Map ( ) ; for ( var x = 0 ; x < n ; x ++ ) { if ( mp . has ( ar [ x ] ) ) mp . set ( ar [ x ] , mp . get ( ar [ x ] ) + 1 ) else mp . set ( ar [ x ] , 1 ) }