C++ | Sliding window | with Set | Simple | with comments
\nclass Solution {\npublic:\n    int longestBeautifulSubstring(string word) {\n        \n       set<char> checker;  //set to store all vowels\n        \n       
```\nclass Solution {\npublic:\n    int longestBeautifulSubstring(string word) {\n        \n       set<char> checker;  //set to store all vowels\n        \n        int start = 0; \n        int end =0;\n        int curr =0;   \n        int ans =0 ; // final answer\n        \n        while(curr<word.size()){\n           \n            \n            if(checker.empty()){   //if set is empty \n                \n                char st = word[curr];   //check is beginning letter is a or not\n                \n                if(st!=\'a\'){\n                    curr++;\n                    \n                }else{\n                    \n                    checker.insert(\'a\');\n                    start = curr;\n                    end = curr;\n                    curr++;\n                   \n                }\n                \n            } else{\n                \n\n                if(word[curr] - word[end]>=0 and (curr== (end+1) or curr==end)){  //if letter are in inc order insert them \n                    \n                  \n                    checker.insert(word[curr]);\n                    \n                 \n                    curr++;\n                    end++;\n                    \n                }else{\n                    \n                    if(checker.size()==5){   //if we have all vowels then size will be 5\n                     \n                        ans = max(ans,end-start+1);\n                        checker.clear();    // clear the set\n                        start = curr;\n                        end = curr;\n                        \n                    }else{                   // not found all vowels discard set , start afresh\n                         checker.clear();\n                        start = curr;\n                        end = curr;\n                        \n                    }\n                    \n                }\n               \n                \n            }\n            \n        }\n\n        if(checker.size()==5){                 //out side the loop case\n                       \n         ans = max(ans,end-start+1);\n         checker.clear();\n                        \n            }\n\n        \n        return ans;\n        \n    }\n};```
['Sliding Window']