Loop to store frequency of the characters in a Map
for ( int i = 0 ; i < n ; i ++ ) if ( mp . containsKey ( s [ i ] ) ) { mp . put ( s [ i ] , mp . get ( s [ i ] ) + 1 ) ; } else { mp . put ( s [ i ] , 1 ) ; }