1839. Longest Substring Of All Vowels in Order - cocoder39/coco39_LC GitHub Wiki

1839. Longest Substring Of All Vowels in Order

class Solution:
    def longestBeautifulSubstring(self, word: str) -> int:
        seen = set()
        left = -1
        res = 0
        for i, ch in enumerate(word):
            if i >= 1 and ch < word[i-1]:
                left = i - 1
                seen = set()
            seen.add(ch)
            if len(seen) == 5:
                res = max(res, i-left)
        return res