Easiest c++ solution solve by counting
IntuitionApproachComplexity
Time complexity: O(n)

Space complexity: O(1)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    vector<char> vowel = {'a', 'e', 'i', 'o', 'u'};
    int longestBeautifulSubstring(string word) {
        int idx = 0, ans = 0, cnt = 0, i;
        for(i = 0;i < word.length();i++){
            if(word[i] == 'a') break;
        }

        for(i;i < word.length();i++){
            if(word[i] == 'u' && (vowel[idx] == 'u' || vowel[idx] == 'o')){
                ans = max(cnt + 1, ans);
            }
            if(word[i] == vowel[idx]) cnt++;
            else if(word[i] == vowel[min(4, idx + 1)] && (word[i - 1] == vowel[idx] || word[i - 1] == vowel[min(4, idx + 1)])){
                idx++;
                cnt++;
            }
            else{
                if(word[i] == 'a') cnt = 1;
                else cnt = 0;
                idx = 0;
            }
        }

        return ans;
    }
};

auto init = []()
{ 
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    return 'c';
}();
```
['String', 'Counting', 'C++']