simple easy brute force  & sliding window
\n# Complexity\n- Time complexity:\n  O(n*n) \n\n- Space complexity:\n  O(1) \n \n\n\nclass Solution {\n  \n\n    public int longestBeautifulSubstring(String wo
\n# Complexity\n- Time complexity:\n  $$O(n*n)$$ \n\n- Space complexity:\n  $$O(1)$$ \n \n```\n\nclass Solution {\n  \n\n    public int longestBeautifulSubstring(String word) {\n        int j=0,ans=0,n=word.length();\n        for(int i=0;i<n;i++){\n            if(word.charAt(i)==\'a\'){\n            int cnt=0;\n            for(j=i+1;j<n && word.charAt(j-1)<=word.charAt(j);j++)\n                cnt+=word.charAt(j-1)<word.charAt(j)?1:0;\n            \n                if(cnt==4) ans=Math.max(ans,j-i);\n                i=j-1;\n            }\n        }\n        return ans;\n\n    }\n}\n```\n# Complexity\n-   Time complexity:\n  $$O(n)$$ \n\n- Space complexity:\n  $$O(1)$$ \n\n# Code\n```\nclass Solution {\n    public int longestBeautifulSubstring(String word) {\n        int n=word.length(),i=0,j=0,ans=0,cnt=1;\n\n        for(j=1;j<n;j++){\n            if(word.charAt(j)>word.charAt(j-1)) cnt++;\n            if(word.charAt(j)<word.charAt(j-1)){\n                cnt=1;\n                i=j;\n            } \n            if(cnt==5) ans=Math.max(ans,j-i+1);\n        }\n        return ans;\n    }\n}\n```\n\n
['Two Pointers', 'String', 'Sliding Window', 'Java']