A string is considered beautiful if it satisfies the following conditions:


	Each of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it.
	The letters must be sorted in alphabetical order (i.e. all 'a's before 'e's, all 'e's before 'i's, etc.).


For example, strings "aeiou" and "aaaaaaeiiiioou" are considered beautiful, but "uaeio", "aeoiu", and "aaaeeeooo" are not beautiful.

Given a string word consisting of English vowels, return the length of the longest beautiful substring of word. If no such substring exists, return 0.

A substring is a contiguous sequence of characters in a string.

&nbsp;
Example 1:

Input: word = "aeiaaioaaaaeiiiiouuuooaauuaeiu"
Output: 13
Explanation: The longest beautiful substring in word is "aaaaeiiiiouuu" of length 13.

Example 2:

Input: word = "aeeeiiiioooauuuaeiou"
Output: 5
Explanation: The longest beautiful substring in word is "aeiou" of length 5.


Example 3:

Input: word = "a"
Output: 0
Explanation: There is no beautiful substring, so return 0.


&nbsp;
Constraints:


	1 &lt;= word.length &lt;= 5 * 105
	word consists of characters 'a', 'e', 'i', 'o', and 'u'.


class Solution:
    def longestBeautifulSubstring(self, word: str) -> int:
        g = ''
        count = m = 0
        for x in word:
            if g and x < g[-1]:
                count = 0
                g = ''
            if not g or x > g[-1]:
                g += x
            count += 1
            if g == 'aeiou':
                m = max(m, count)
        return m
class Solution {
    public int longestBeautifulSubstring(String word) {
      int max = 0;
      for(int i = 1;i<word.length();i++){
         int temp = 1;
         Set<Character> verify = new HashSet<>();
         verify.add(word.charAt(i-1));
         while(i < word.length() && word.charAt(i) >= word.charAt(i-1)){
            temp++;
            verify.add(word.charAt(i));
            i++;
         }
         max = verify.size() == 5 ? Math.max(max,temp) : max ;
      }

      return max;
    }
}
class Solution {
public:
    int longestBeautifulSubstring(string word) {
        const auto n = word.size();

        int cnt = 1;
        int len = 1;
        int max_len = 0;
        for (int i = 1; i != n; ++i) {
            if (word[i - 1] == word[i]) {
                ++len;
            } else if (word[i - 1] < word[i]) {
                ++len;
                ++cnt;
            } else {
                cnt = 1;
                len = 1;
            }

            if (cnt == 5) {
                max_len = max(max_len, len);
            }
        }
        return max_len;
    }
};
/**
 * @param {string} word
 * @return {number}
 */
var longestBeautifulSubstring = function(word) {
   
    let obj = { 'a': 1, 'e': 2, 'i': 3, 'o': 4, 'u': 5 }
    let seq = 0
    let maxstrcount = 0, strcount = ""
    for (let i = 0; i <= word.length; i++) {
        if (seq <= obj[word[i]]) {
            strcount += word[i]
            seq = obj[word[i]]
        } else {
            let set = new Set()
            for (let i = 0; i < strcount.length; i++) {
                set.add(strcount[i])
            }
            if (set.size == 5) {
                maxstrcount = Math.max(strcount.length, maxstrcount)
            }
            if (i < word.length - 1)
                i--
            strcount = ""
            seq = 0
        }
    }
    return maxstrcount
};
Longest Substring Of All Vowels in Order