<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the maximum number of vowel letters in any substring of </em><code>s</code><em> with length </em><code>k</code>.</p>

<p><strong>Vowel letters</strong> in English are <code>&#39;a&#39;</code>, <code>&#39;e&#39;</code>, <code>&#39;i&#39;</code>, <code>&#39;o&#39;</code>, and <code>&#39;u&#39;</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;abciiidef&quot;, k = 3
<strong>Output:</strong> 3
<strong>Explanation:</strong> The substring &quot;iii&quot; contains 3 vowel letters.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aeiou&quot;, k = 2
<strong>Output:</strong> 2
<strong>Explanation:</strong> Any substring of length 2 contains 2 vowels.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;leetcode&quot;, k = 3
<strong>Output:</strong> 2
<strong>Explanation:</strong> &quot;lee&quot;, &quot;eet&quot; and &quot;ode&quot; contain 2 vowels.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
	<li><code>1 &lt;= k &lt;= s.length</code></li>
</ul>

class Solution {
public:
    // helper function
    bool isVowel(char letter) {
        switch (letter) {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
            return true;
        default:
            return false;
        }
    }

    int maxVowels(string s, int k) {

        int index = 0;
        int max_vowels;
        int num_vowels = 0;

        string kstring = s.substr(0, k);

        // get the initial substring
        for (int i = 0; i < kstring.size(); i++) {
            if (isVowel(kstring[i])) {
                num_vowels++;
            }
        }

        max_vowels = num_vowels;
        // index++;
        // cout << "initial subtring " << kstring << " has " << max_vowels << " vowels" << endl;

        while ((index + k) < s.size()) {
            // kstring = s.substr(index, k);
            // cout << "kstring: " << kstring << endl;
            // check next value
            if(isVowel(s[index+k])){
                // cout << "index " << index+k << " is a vowel" << endl;
                num_vowels++;
            }
            // check 0 of substr
            if(isVowel(s[index])) {
                // cout << "0th of kstring is not a vowel" << endl;
                num_vowels--;
            }
            // compare to max_vowels
            if (max_vowels < num_vowels) {
                cout << "new max vowels is " << num_vowels << endl;
                max_vowels = num_vowels;
            }

            index++;
        }
        return max_vowels;
    }
};
11900