Map M will store the frequency of each element in the array
Map < Integer , Integer > mp = new HashMap < > ( ) ; for ( int x = 0 ; x < n ; x ++ ) mp . put ( arr [ x ] , mp . getOrDefault ( arr [ x ] , 0 ) + 1 ) ;