Find the Longest Substring Containing Vowels in Even Counts
Real-world version: The Longest Stretch With Every Tally EvenThe 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.
def find_the_longest_substring(line: str) -> int:public int findTheLongestSubstring(String line)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Number of Wonderful SubstringsReal-world version: Nearly Even Telemetry StretchesMedium
- Unique Length-3 Palindromic SubsequencesReal-world version: Three-Letter Mirrored PicksMedium
- Find the DifferenceReal-world version: The Sort That Joined the TrayEasy
- Longest Nice SubstringReal-world version: Longest Matched-Case RunEasy