map is used to store character frequencies
Map < Character , Integer > m = new HashMap < > ( ) ; for ( i = 0 ; i < s . length ; i ++ ) { if ( m . containsKey ( s [ i ] ) ) { m . put ( s [ i ] , m . get ( s [ i ] ) + 1 ) ; } else { m . put ( s [ i ] , 1 ) ; } } int result = 0 ; int flag = 0 ;