Find the Longest Substring Containing Vowels in Even Counts
Medium · Hash Table, String, Bit Manipulation, Prefix Sum
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1
Input: s = "eleetminicoworoep" Output: 13
The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u.
Example 2
Input: s = "leetcodeisgreat" Output: 5
The longest substring is "leetc" which contains two e's.
Example 3
Input: s = "bcbcbc" Output: 6
In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.
Constraints
- 1 <= s.length <= 5 x 10^5
- s contains only lowercase English letters.
Starter code (python)
class Solution(object):
def findTheLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
Related problems
- Two Sum (Easy)
- Longest Substring Without Repeating Characters (Medium)
- Longest Palindromic Substring (Medium)
Previous: Check If N and Its Double Exist · Next: Count Negative Numbers in a Sorted Matrix · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.