Map to store the frequency of each element
let mp = new Map ( ) ; let ans = 1 , cnt = n ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . has ( ar [ i ] ) ) { mp . set ( ar [ i ] , mp . get ( ar [ i ] ) + 1 ) } else { mp . set ( ar [ i ] , 1 ) } }