Length of the longest substring consisting only of vowels in non | Function to find length of the longest substring consisting only of vowels in non - increasing order ; Stores all vowels in decreasing order ; Stores current index of array ch [ ] ; Stores the result ; Stores the count of current substring ; Declare a HashSet to store the vowels ; Traverse the string , S ; If S [ i ] is equal to ch [ j ] ; Increment count by 1 ; Add S [ i ] in the mp ; If length of mp is 5 , update res ; Else if j + 1 is less than 5 and S [ i ] is equal to ch [ j + 1 ] ; Add the S [ i ] in the mp ; Increment count by 1 ; Increment j by 1 ; If length of mp is 5 , update res ; Clear the mp ; If S [ i ] is ' u ' ; Add S [ i ] in the mp ; Update j and assign 1 to count ; Else assign 0 to j and count ; Return the result ; Given Input ; Function Call
function count ( S , N ) { let ch = [ ' ' , ' ' , ' ' , ' ' , ' ' ] ; let j = 0 ; let res = 0 ; let count = 0 ; let mp = new Map ( ) ; for ( let i = 0 ; i < N ; ++ i ) { if ( S [ i ] == ch [ j ] ) { ++ count ; mp . set ( S [ i ] , " " ) ; if ( mp . size == 5 ) { res = Math . max ( res , count ) ; } } else if ( j + 1 < 5 && S [ i ] == ch [ j + 1 ] ) { mp . set ( S [ i ] , " " ) ; ++ count ; j ++ ; if ( mp . size == 5 ) { res = Math . max ( res , count ) ; } } else { mp . clear ( ) ; if ( S [ i ] == ' ' ) { mp . set ( ' ' , " " ) ; j = 0 ; count = 1 ; } else { j = 0 ; count = 0 ; } } } return res ; } let S = " " ; let N = S . length ; document . write ( count ( S , N ) ) ;