Longest substring of vowels with no two adjacent alphabets same | Function to check a character is vowel or not ; Function to find length of longest substring consisting only of vowels and no similar adjacent alphabets ; Stores max length of valid subString ; Stores length of current valid subString ; If curr and prev character are not same , include it ; If same as prev one , start new subString from here ; Store max in maxLen ; Driver code
function isVowel ( x ) { return x === " " || x === " " || x === " " || x === " " || x === " " ; } function findMaxLen ( s ) { var maxLen = 0 ; var cur ; if ( isVowel ( s [ 0 ] ) ) maxLen = 1 ; cur = maxLen ; for ( var i = 1 ; i < s . length ; i ++ ) { if ( isVowel ( s [ i ] ) ) { if ( s [ i ] !== s [ i - 1 ] ) cur += 1 ; else cur = 1 ; } else { cur = 0 ; } maxLen = Math . max ( cur , maxLen ) ; } return maxLen ; } var Str = " " ; document . write ( findMaxLen ( Str ) ) ;