Brute Force
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int longestBeautifulSubstring(string s) {\n        int n=s.size();\n        int i=0;\n        int maxi=0;\n        if(s.size()<5)\n        {\n            return 0;\n        }\n        while(i<n-4)\n        {\n            if(s[i]==\'a\')\n            {\n                int j=i+1;\n                int cnt=1;\n                char prev=\'a\';\n                while(j<n){\n                    if(prev==\'a\')\n                    {\n                        if(s[j]==\'a\' or s[j]==\'e\'){\n                            prev=s[j];\n                            cnt++;\n                            j++;\n                        }\n                        else{\n                            break;\n                        }\n                    }\n                    else if(prev==\'e\'){\n                        if(s[j]==\'e\' or s[j]==\'i\'){\n                            prev=s[j];\n                            cnt++;\n                            j++;\n                        }\n                        else{\n                            break;\n                        }\n                    }\n                    else if(prev==\'i\'){\n                        if(s[j]==\'i\' or s[j]==\'o\'){\n                            prev=s[j];\n                            cnt++;\n                            j++;\n                        }\n                        else{\n                            break;\n                        }\n                    }\n                    else if(prev==\'o\'){\n                        if(s[j]==\'o\' or s[j]==\'u\'){\n                            prev=s[j];\n                            cnt++;\n                            j++;\n                        }\n                        else{\n                            break;\n                        }\n                    }\n                    else if(prev==\'u\'){\n                        if(s[j]==\'u\'){\n                            prev=s[j];\n                            cnt++;\n                            j++;\n                        }\n                        else{\n                            break;\n                        }\n                    }\n                    if(prev==\'u\'){\n                        maxi=max(maxi,cnt);\n                    }\n                }\n                //maxi=max(maxi,cnt);\n                i=j;\n            }\n            else{\n                i++;\n            }\n        }\n        return maxi;\n    }\n};\n```
['C++']