Longest substring of vowels | CPP program to find the longest substring of vowels . ; Increment current count if s [ i ] is vowel ; check previous value is greater then or not ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isVowel ( char c ) { return ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } int longestVowel ( string s ) { int count = 0 , res = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( isVowel ( s [ i ] ) ) count ++ ; else { res = max ( res , count ) ; count = 0 ; } } return max ( res , count ) ; } int main ( ) { string s = " theeare " ; cout << longestVowel ( s ) << endl ; return 0 ; }