[Python] fast and simple
\nclass Solution:\n    def longestBeautifulSubstring(self, word: str) -> int:\n        begin = None\n        best = 0\n        a_detected = False\n        for i
```\nclass Solution:\n    def longestBeautifulSubstring(self, word: str) -> int:\n        begin = None\n        best = 0\n        a_detected = False\n        for index, value in enumerate(word):\n            if not a_detected and value == \'a\':\n                begin = index\n                a_detected = True\n            elif a_detected and value < word[index-1]:\n                if len(set(word[begin:index])) == 5:\n                    best = max(best, len(word[begin:index]))\n                if value == \'a\':\n                    begin = index\n                else:\n                    begin = None\n                    a_detected = False\n        best = max(best, len(word[begin:])) if a_detected and len(set(word[begin:])) == 5 else best\n        return best\n```
['Python', 'Python3']