PracticeStrings
Longest Vowel Streak
Context
A word is treated as a sequence of lowercase letters. Among its letters, the vowel class is {a, e, i, o, u}. Determine the greatest number of consecutive positions occupied by vowels.
Problem
Implement a function that returns the length of the longest contiguous substring made entirely of lowercase vowels. A vowel extends the current streak. Any consonant ends that streak and makes the current length zero. Return 0 when the string is empty or contains no vowels. A streak ending at the final character must be included, and equal longest streaks do not need separate handling. Scan the string once using constant auxiliary space.
Examples
Example 1
Input:
word = "beautiful"Output:
3Explanation: The executed call on "beautiful" returns 3.
Example 2
Input:
word = "rhythms"Output:
0Explanation: The executed call on "rhythms" returns 0.
Example 3
Input:
word = "queueing"Output:
5Explanation: The executed call on "queueing" returns 5.
Constraints
0 <= len(word) <= 100000word: alphabet lowercaseword contains only lowercase letters.- Types:
wordis str; result is int
Function signature
def longest_vowel_streak(word: str) -> int
wordstr- A sequence of lowercase letters to inspect.
- returns int
- The maximum number of consecutive vowels in word, or 0 if no vowel occurs.
Adapted from MBPP problem task_806 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Code
Saved