for ( int i = 0 ; i < s . Length ; i ++ ) update the frequency
{ if ( m . ContainsKey ( s [ i ] ) ) { var c = m [ s [ i ] ] + 1 ; m . Remove ( s [ i ] ) ; m . Add ( s [ i ] , c ) ; } else { m . Add ( s [ i ] , 1 ) ; } }