Count number of occurrence of a charterer in the string
Dictionary < char , int > mp = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( str [ i ] ) ) { var val = mp [ str [ i ] ] ; mp . Remove ( str [ i ] ) ; mp . Add ( str [ i ] , val + 1 ) ; } else { mp . Add ( str [ i ] , 1 ) ; } }