C++ | O(n) Simple Solution
```\nclass Solution {\npublic:\n    int longestBeautifulSubstring(string word) {\n        vector vowels{\'a\',\'e\',\'i\',\'o\',\'u\'};\n        int result = 0;
```\nclass Solution {\npublic:\n    int longestBeautifulSubstring(string word) {\n        vector<char> vowels{\'a\',\'e\',\'i\',\'o\',\'u\'};\n        int result = 0;\n        int currPos = 0;\n        int runningLength = 0;\n        \n        for(int i=0;i<word.size();i++)\n        {\n            if(word[i]==\'a\')\n            {\n                runningLength = (currPos==1 ? runningLength : 0 ) + 1;\n                currPos = 1;\n            }\n            else if (currPos<5 && word[i] == vowels[currPos])\n            {\n                currPos++;\n                runningLength++;\n            }\n            else if(currPos>0 && word[i]==vowels[currPos-1])\n            {\n                runningLength++;\n            }\n            else\n            {\n                runningLength = 0;\n                currPos = 0;\n            }\n            \n            if(currPos==5)\n            {\n                result = max(result, runningLength);\n            }\n                        \n        }\n        \n        return result;\n        \n    }\n};
[]