Store frequency of each character
for ( int i = 0 ; i < n ; i ++ ) { if ( freq . ContainsKey ( ( int ) s [ i ] ) ) { freq [ ( int ) s [ i ] ] = freq [ ( int ) s [ i ] ] + 1 ; } else { freq . Add ( ( int ) s [ i ] , 1 ) ; } } List < int > v = new List < int > ( ) ;