Trains the technique from
LeetCode 1371Find the Longest Substring Containing Vowels in Even CountsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
The only tallied letter here is a and it turns up twice, so the whole line is balanced.
Example 2
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
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.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_the_longest_substring(line: str) -> int:public int findTheLongestSubstring(String line)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.