C++ O(n) time  , O(1) space
//keep record of previously appeared all vowels in order.\nclass Solution {\n\npublic:\n    int longestBeautifulSubstring(string word) {\n        \n        int 
//keep record of previously appeared all vowels in order.\nclass Solution {\n\npublic:\n    int longestBeautifulSubstring(string word) {\n        \n        int ans = 0;\n        int count=0;\n        int fa=0;\n        int fe=0;\n        int fo=0;\n        int fi=0;\n        int fu=0;\n        if(word[0]==\'a\') {\n            fa=1;\n            count++;\n        }\n        \n        for(int i =1;i<word.length();i++){\n            if(word[i]==\'a\') fa=1;\n            if(word[i]==\'e\'&&fa) fe=1;\n            if(word[i]==\'i\'&&fa&&fe) fi=1;\n            if(word[i]==\'o\'&&fe&&fa&&fi) fo=1;\n            if(word[i]==\'u\'&&fa&&fe&&fo&&fi) fu=1;\n\n            if(word[i]>=word[i-1]) count++;\n            else {\n                if(fa&&fe&&fi&&fo&&fu){\n                    \n                    ans=max(ans,count);\n                }\n                    fa=0;\n                    fe=0;\n                    fo=0;\n                    fi=0;\n                    fu=0;\n                if(word[i]==\'a\'){\n                    fa=1;\n                    count=1;\n                }\n                else count = 0;\n            }\n\t\t\t//Case when last letter is u itself.\n            if(fa&&fe&&fi&&fo&&fu)\n             ans=max(ans,count);\n        }\n        return ans;\n        \n    }\n};
[]