Store the indices which contains the vowels
vector < int > indices ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' a ' s [ i ] == ' e ' s [ i ] == ' o ' s [ i ] == ' i ' s [ i ] == ' u ' ) { counts [ s [ i ] ] ++ ; indices . push_back ( i ) ; } }