Store the indices which contains the vowels
List < int > indices = new List < int > ( ) ; for ( i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' a ' s [ i ] == ' e ' s [ i ] == ' o ' s [ i ] == ' i ' s [ i ] == ' u ' ) { if ( counts . ContainsKey ( s [ i ] ) ) { counts [ s [ i ] ] = counts [ s [ i ] ] + 1 ; } else { counts . Add ( s [ i ] , 1 ) ; } indices . Add ( i ) ; } }