[Java] O(N) sliding window | 18ms
\nclass Solution {\n    public int longestBeautifulSubstring(String word) {\n        int maxLen = 0;\n        for (int i = 0; i < word.length();) {\n           
```\nclass Solution {\n    public int longestBeautifulSubstring(String word) {\n        int maxLen = 0;\n        for (int i = 0; i < word.length();) {\n            int start = i, cnt = 1, cur = word.charAt(i);\n            while (i < word.length() && cur <= word.charAt(i)) {\n                if (cur < word.charAt(i)) {\n                    cur = word.charAt(i);\n                    ++cnt;\n                }\n                ++i;\n            }\n            if (cnt == 5) {\n                maxLen = Math.max(i - start, maxLen);\n            }\n        }\n        return maxLen;\n    }\n}\n```
['Sliding Window', 'Java']