Python Sliding Window
So here is the method of thinking. \nThink brute force first. If you can\'t get the brute force correct you have never understood sliding window. For every ques
So here is the method of thinking. \nThink brute force first. If you can\'t get the brute force correct you have never understood sliding window. For every question out there in sliding window no matter how easy/hard it is solve it using brute force even if you know the answer. Understand very clearly in the brute force what is being repeated in every iteration. Figure out how you can use the previous iteration in the new iteration. If you can figure out this, then sliding window comes down to just coding. Stick to a pattern that you can get comfortable with and solve every question with just one rule\nBrute first -> Sliding window next using the patttern you have learnt all the along the way. \n\n\n```\nclass Solution:\n    def longestBeautifulSubstring(self, word: str) -> int:\n        maxlen = 0\n        order = {"a": 0, "e": 1, "i": 2, "o": 3, "u": 4}\n        \n        if len(word) == 0:\n            return 0\n        prev = word[0]\n        seen = set(prev)\n        start = 1\n        for end, char in enumerate(word, 1):\n            if order[char] >= order[prev]:\n                seen.add(char)\n                if len(seen) == 5:\n                    maxlen = max(maxlen, end - start + 1)\n                prev = char\n            elif order[char] < order[prev]:\n                seen = set()\n                seen.add(char)\n                start = end\n                prev = char\n            else:\n                seen.add(char)\n                prev = char\n        return maxlen\n            \n```
[]