C++ Simple | Easy To Understand
\nclass Solution {\npublic:\n    int longestBeautifulSubstring(string str) {\n        \tint a = str.length();\n\tint vowel = 0;\n\tint r = 0;\n\tint maxi = 0;\n
```\nclass Solution {\npublic:\n    int longestBeautifulSubstring(string str) {\n        \tint a = str.length();\n\tint vowel = 0;\n\tint r = 0;\n\tint maxi = 0;\n\tchar last = \'a\';\n\tfor (int i = 0; i < a; i++) {\n\t\tif (str[i] == \'a\') {\n\t\t\tr = i;\n            vowel++;\n\t\t\tbreak;\n\t\t}\n\t}\n        if (vowel==0)return 0;\n\tfor (int x = r + 1; x < a; x++) {\n\t\tif (str[x] >= last) {\n\t\t\tif (str[x] != last)\n\t\t\t\tvowel++;\n\t\t\tlast = str[x];\n\t\t}\n\t\telse {\n\t\t\tvowel = 1;\n\t\t\tr = x;\n\t\t\tlast = str[x];\n\t\t}\n\t\tif (vowel >= 5) {\n\t\t\tmaxi = max(maxi, x - r + 1);\n\t\t}\n\t}\nreturn maxi;\n    }\n};\n```
[]