Java O(n) solution O(1) space,  easy to understand. with alternative sliding window solution.
\nSimple solution \n\nBelow solution runs faster then sliding window.\n\n\n    public int longestBeautifulSubstring(String str) {\n        char[] vowels = {\'a\
\nSimple solution \n\nBelow solution runs faster then sliding window.\n\n```\n    public int longestBeautifulSubstring(String str) {\n        char[] vowels = {\'a\', \'e\', \'i\', \'o\', \'u\'};\n        int count = 0, i =0, max = 0, j = 0;\n        \n        while (i < str.length()) {\n            if (j >= vowels.length) {\n                j = 0;\n            }\n\n            if (str.charAt(i) == vowels[j]) {\n                // string char == previous vowel\n                count++; \n            }  else if (j < vowels.length-1 && str.charAt(i) == vowels[j+1] && count > 0) {\n                // string char is next vowel, a -> e\n                count++; j++;\n            }  else {\n                // precondition break\n                j= 0; count = str.charAt(i) == vowels[j] ? 1:0;\n            }\n            i++;\n            if (j == 4) {\n                max = Math.max(max, count);\n            }\n        }\n\n        return max;\n    }\n```\n\n\nSliding window solution \n\n```\n    public int longestBeautifulSubstring(String word) {\n        int max = 0;\n        Set<Character> set = new HashSet<>();\n        int start = 0,end = 0;\n        int n = word.length();\n        \n        while(end < n){\n            \n            if(end > 0 && word.charAt(end) < word.charAt(end-1)){\n                set.clear();\n                start = end;\n            }\n            set.add(word.charAt(end));\n            \n            if(set.size() == 5)\n                max = Math.max(max,end-start+1);\n            end++;\n             \n        }\n        return max;\n    }\n```
[]