JAVA||Sliding window||O(n)||Clear solution
Please upvote if you find it useful! Or leave comments or suggestions below!\nI will try my best to answer them! Thank you!!\n\nclass Solution {\n    public int
Please upvote if you find it useful! Or leave comments or suggestions below!\nI will try my best to answer them! Thank you!!\n```\nclass Solution {\n    public int longestBeautifulSubstring(String word) {\n        // the last \'u\' is the sentinel value\n        char[] vowels = new char[]{\'a\', \'e\', \'i\', \'o\', \'u\', \'u\'};\n        int left = 0, right = 0, vIdx = 0, maxLen = 0;\n        \n        while (left < word.length()) {\n            char leftChar = word.charAt(left);\n            \n            if (leftChar == \'a\') {\n                right = left;\n                \n                while (right < word.length()) {\n                    char rightChar = word.charAt(right);\n                    char nextVowel = vowels[vIdx + 1];\n                    \n                    if (rightChar != vowels[vIdx]) {\n                        if (rightChar != nextVowel) {\n                            break;\n                        } else {\n                            vIdx++;\n                        }\n                    }\n                    right++;\n                }\n                \n                if (vIdx == 4) maxLen = Math.max(maxLen, right - left);\n                left = right - 1;\n            }\n            \n            vIdx = 0;\n            left++;\n        }\n        \n        return maxLen;\n    }\n}\n\n```
[]