map is used to store character frequencies
Dictionary < char , int > mp = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( mp . ContainsKey ( s [ i ] ) ) { var v = mp [ s [ i ] ] + 1 ; mp . Remove ( s [ i ] ) ; mp . Add ( s [ i ] , v ) ; } else { mp . Add ( s [ i ] , 1 ) ; } } int result = 0 ; int flag = 0 ;