[Python3] Simple One Pass Greedy Solution
\nclass Solution:\n    def longestBeautifulSubstring(self, word: str) -> int:\n        vowels = {\'a\' : 0, \'e\' : 1, \'i\' : 2, \'o\' : 3, \'u\' : 4}\n       
```\nclass Solution:\n    def longestBeautifulSubstring(self, word: str) -> int:\n        vowels = {\'a\' : 0, \'e\' : 1, \'i\' : 2, \'o\' : 3, \'u\' : 4}\n        n = len(word)\n        last = \'#\'\n        j = 0\n        res = 0\n        for i in range(n):\n            if word[i] in vowels:\n                if last == \'#\' and word[i] == \'a\':\n                    j = i\n                    last = \'a\'\n                elif last != \'#\' and (vowels[last] == vowels[word[i]] or vowels[last] + 1 == vowels[word[i]]):\n                    last = word[i]\n                elif last != \'#\':\n                    j = i\n                    if word[i] == \'a\':\n                        last = \'a\'\n                    else:\n                        last = \'#\'\n            if last == \'u\':\n                res = max(res, i - j + 1)\n        return res\n```
[]