Longest substring of vowels with no two adjacent alphabets same | Function to check a character is vowel or not ; Function to check a substring is valid or not ; If size is 1 then check only first character ; If 0 'th character is  not vowel then invalid ; If two adjacent characters are same or i 'th char is  not vowel then invalid ; Function to find length of longest substring consisting only of vowels and no similar adjacent alphabets ; Stores max length of valid substring ; For current substring ; Check if substring is valid ; Size of substring is ( j - i + 1 ) ; Driver code
def isVowel ( c ) : NEW_LINE INDENT return ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) NEW_LINE DEDENT def isValid ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE if ( n == 1 ) : NEW_LINE INDENT return ( isVowel ( s [ 0 ] ) ) NEW_LINE DEDENT if ( isVowel ( s [ 0 ] ) == False ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT if ( s [ i ] == s [ i - 1 ] or not isVowel ( s [ i ] ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def findMaxLen ( s ) : NEW_LINE INDENT maxLen = 0 NEW_LINE n = len ( s ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT temp = " " NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT temp = temp + s [ j ] NEW_LINE if ( isValid ( temp ) ) : NEW_LINE INDENT maxLen = ( max ( maxLen , ( j - i + 1 ) ) ) NEW_LINE DEDENT DEDENT DEDENT return maxLen NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT Str = " aeoibsddaeiouudb " NEW_LINE print ( findMaxLen ( Str ) ) NEW_LINE DEDENT