Show problems as
Classic problem #1371MediumHash TableStringBit ManipulationPrefix Sum

Find the Longest Substring Containing Vowels in Even Counts

Real-world version: The Longest Stretch With Every Tally Even
Tracked in this browser only
Read Find the Longest Substring Containing Vowels in Even Counts on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A line line holds only lowercase letters. The five letters a, e, i, o and u are the tallied letters, and the other twenty-one are ignored.

A stretch of neighbouring letters is balanced when every tallied letter appears an even number of times inside it, and appearing no times at all counts as even.

Return the length of the longest balanced stretch. The empty stretch is balanced, so the answer is never below zero.

Examples

Example 1

Input
line = "abcabc"
Output
6

The only tallied letter here is a and it turns up twice, so the whole line is balanced.

Example 2

Input
line = "ae"
Output
0

One a and one e, each an odd number of times, and dropping either letter leaves the other odd, so nothing but the empty stretch is balanced.

Example 3

Input
line = "azbzc"
Output
4

The single a is tallied once, so a balanced stretch has to leave it out. The four letters after it hold no tallied letter at all.

Constraints

  • 1 <= line.length <= 5 * 10^5
  • line holds only lowercase English letters

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def find_the_longest_substring(line: str) -> int:
Java
public int findTheLongestSubstring(String line)