C++ || Sliding Window || Time Complexity - O(N)
\nclass Solution {\npublic:\n    int longestBeautifulSubstring(string word) {\n        int n = word.size(); \n        if(n < 5){\n            return 0;\n       
```\nclass Solution {\npublic:\n    int longestBeautifulSubstring(string word) {\n        int n = word.size(); \n        if(n < 5){\n            return 0;\n        }\n        unordered_map<char,char> m;\n        m[\'a\'] = \'e\', m[\'e\'] = \'i\', m[\'i\'] = \'o\', m[\'o\'] = \'u\';\n        int maxlen = 0, i = 0;\n        while(i < n){\n            if(word[i] == \'a\'){\n                // Continue expanding the window till the point you get valid characters in correct order\n                int j = i;\n                for(; j+1 < n; j++){\n                    // If at character a -> next will be \'a\' or \'e\'\n                    // It at character e -> next will be \'e\' or \'i\'\n                    // It at character i -> next will be \'i\' or \'o\'\n                    // It at character o -> next will be \'o\' or \'u\'\n                    // It at character u -> next will be \'u\' otherwise stop (Now you cant expand current window)\n                    if(word[j+1] == word[j] or (m.count(word[j]) && (word[j+1] == m[word[j]]))){\n                        continue;\n                    }else{\n                        break;\n                    }\n                }\n                // Current window is valid iff j points at \'u\'\n                if(word[j] == \'u\'){\n                    maxlen = max(maxlen, j-i+1);\n                }\n                // Next valid window will start at j+1\n                i = j;\n            }\n            i++;\n        }\n        return maxlen;\n    }\n};\n```
['Sliding Window']