Count of substrings consisting only of vowels | Function to check vowel or not ; Function to find largest string which satisfy condition ; Check if current character is vowel ; Increment count ; Count all possible substrings of calculated length ; Reset the length ; Add remaining possible substrings consisting of vowels occupying last indices of the string ; Driver code
function isvowel ( x ) { return ( x == ' ' x == ' ' x == ' ' x == ' ' x == ' ' ) ; } function CountTotal ( str ) { let ans = 0 ; let n = str . length ; let s = str . split ( ' ' ) ; let cnt = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isvowel ( s [ i ] ) ) cnt += 1 ; else { ans += ( cnt * ( cnt + 1 ) / 2 ) ; cnt = 0 ; } } if ( cnt != 0 ) ans += ( cnt * ( cnt + 1 ) / 2 ) ; return ans ; } let s = " " ; document . write ( CountTotal ( s ) ) ;