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 invalidlen ; 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
function isVowel ( c ) { return ( c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' ) ; } function isValid ( s ) { let n = s . length ; if ( n == 1 ) return ( isVowel ( s [ 0 ] ) ) ; if ( isVowel ( s [ 0 ] ) == false ) return false ; for ( let i = 1 ; i < n ; i ++ ) { if ( s [ i ] == s [ i - 1 ] || ! isVowel ( s [ i ] ) ) return false ; } return true ; } function findMaxLen ( s ) { let maxLen = 0 ; let n = s . length ; for ( let i = 0 ; i < n ; i ++ ) { let temp = " " ; for ( let j = i ; j < n ; j ++ ) { temp = temp + s [ j ] ; if ( isValid ( temp ) ) maxLen = Math . max ( maxLen , ( j - i + 1 ) ) ; } } return maxLen ; } let Str = " " ; document . write ( findMaxLen ( Str ) ) ;