C++ | Easy to Understand | Sliding Window
Intuition
start traversing the string
for every a that you encounter find the max valid window starting from this position
Approach
we initialize two pointers:
# Intuition
- start traversing the string 
- for every `a` that you encounter find the max valid window starting from this position  
# Approach
- we initialize two pointers: `start` and `end` 
- if the current character is `a` then start expanding the window till it becomes invalid -> if we exceed the length or we break the sequence of vowels
- next we check if we have seen all the vowels in the current window, if so this window is valid and we can update our answer
- finally we skip to last position where the window became invalid as we dont need to process the previous substring since it is already invalid

# Complexity
- Time complexity:
O(n)
- Space complexity:
O(1)
# Code
```cpp []
class Solution {
public:
    int longestBeautifulSubstring(string word) {
        int start = 0 , res = 0 ;
        string vw = "aeiou" ;
        for(int i = 0 ; i < word.size() ; i++){
            if(word[i] == 'a'){
                int j = i + 1 ;
                unordered_set<char> s ;
                s.insert(word[i]) ;
                while(
                    j < word.length() && 
                    (
                        // the current char can either be equal to the previous char 
                        // or 1 + previous char w.r.t its position in the sequence aka vw
                        word[j] == word[j-1] || 
                        vw.find(word[j]) == vw.find(word[j-1]) + 1
                    )
                ) s.insert(word[j++]) ;
                j = j - 1 ;
                if(s.size() == 5) res = max(res,j-i+1) ;
                i = j ;
            }
        }
        return res ;
    }
};
```
['String', 'Sliding Window', 'C++']