111. Even Vowel Window

A text-analysis tool receives a string s of lowercase English letters. The five vowels are a, e, i, o and u; every other letter is a consonant. A substring is called calm if each of the five vowels appears an even number of times inside it. A vowel that does not appear at all counts as zero occurrences, which is even, and consonants are ignored completely.

Return the length of the longest calm substring of s. The empty substring is calm, so the answer is never negative, and a string with no vowels is calm as a whole.

Example 1

Input:
s = "banana"
Output:
5
Explanation:

The substring "banan" holds two a's and no other vowel, giving length 5; the whole string has three a's.

Example 2

Input:
s = "xyz"
Output:
3
Explanation:

There are no vowels at all, so the entire string is calm.

Example 3

Input:
s = "audio"
Output:
1
Explanation:

Every window containing a vowel has some vowel with an odd count, so only the single letter "d" is calm.

Constraints

1 ≤ s.length ≤ 2 * 105

s consists of lowercase English letters

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Time per case
Python 1,200 msC++ 300 msJava 600 msJavaScript 600 msTypeScript 600 ms

Expected complexity

Time
O(n)
Space
O(1)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…