stores the frequency of each element
let count = new Map ( ) ; if ( n < 4 ) return 0 ; for ( let i = 0 ; i < n ; i ++ ) { count . set ( arr [ i ] , ( count . get ( arr [ i ] ) == null ? 0 : count . get ( arr [ i ] ) + 1 ) ) ; }