Find the Longest Substring Containing Vowels in Even Counts

Medium Topics Company Tags

Return the length of the longest contiguous substring of s in which each vowel (a, e, i, o, and u) occurs an even number of times. Zero occurrences is even. Consonants have no restrictions.

Example 1:

Input: s = "aaeb"

Output: 2

Explanation: The substring "aa" has two occurrences of a and zero of every other vowel, giving length 2. Every longer substring contains the lone e an odd number of times.

Example 2:

Input: s = "bcdf"

Output: 4

Explanation: The whole string has zero occurrences of every vowel. Zero is even, so all four characters qualify.

Example 3:

Input: s = "aeiouaeiou"

Output: 10

Explanation: The entire string contains each vowel exactly twice, so its full length of 10 qualifies.

Constraints:

  • 1 <= s.length <= 500000
  • Only lowercase English letters occur.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.