C++ | (Two pointers) | (Simple and elegant)
PLz do upvote if you find it helpful!!!!\nMaintain two pointers left and right and a map.\nNow we will move on to the right freely,also put elements into the ma
PLz do upvote if you find it helpful!!!!\nMaintain two pointers left and right and a map.\nNow we will move on to the right freely,also put elements into the map as we move on the way until: we find a vowel which precedes the previous letter in the alphabet.\nIf that happens we will check the map size first,if its 5 we will store it in a temporary result \nthen,we will clear the map(dont forget to do this)\nand after that we will move the left pointer till it reaches the right pointer.\n\nthen the same steps are repeated again.\n\nbe careful to check the map once again after a complete traversal.\n//see the second test case carefully\n\n\n```\nclass Solution {\npublic:\n    int longestBeautifulSubstring(string s) {\n        int left=0;\n        int right=0;\n        int res=0;\n        map<char,int> m;\n        int n=s.length();\n        while(right<n){  \n            if(right>0 and ((int)(s[right]-\'a\')<(int)(s[right-1]-\'a\'))){\n              if(m.size()==5){ // a probable result has arrived\n                  res=max(res,right-left);\n              }\n             \n              m.clear();\n              while(left!=right){\n                  left++;\n              }   \n            }\n            m[s[right]]++;\n            right++;\n        }\n        if(m.size()==5){ //the last right to left pointer\n            res=max(res,right-left);\n        }\n        return res;\n    }\n};\n```\n\nIf you found this useful,plz upvote!!!!\nKEEP CODING!!
[]