Update frequency of A [ i ]
if ( frequency . containsKey ( A [ i ] ) ) { frequency . replace ( A [ i ] , frequency . get ( A [ i ] ) + 1 ) ; } else { frequency . put ( A [ i ] , 1 ) ; } } for ( Map . Entry it : frequency . entrySet ( ) ) {