Building Dictionary to store frequencies of all characters .
Dictionary < char , int > hm = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < temp . Length ; i ++ ) { if ( hm . ContainsKey ( temp [ i ] ) ) hm [ temp [ i ] ] = hm [ temp [ i ] ] + 1 ; else hm . Add ( temp [ i ] , 1 ) ; }