PracticeStrings

Longest Vowel Streak

BeginnerStringstraversalaccumulationstate tracking Time not estimated Not started

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: 3
Explanation: The executed call on "beautiful" returns 3.
Example 2
Input: word = "rhythms"
Output: 0
Explanation: The executed call on "rhythms" returns 0.
Example 3
Input: word = "queueing"
Output: 5
Explanation: The executed call on "queueing" returns 5.

Constraints

  • 0 <= len(word) <= 100000
  • word: alphabet lowercase
  • word contains only lowercase letters.
  • Types: word is str; result is int

Function signature

def longest_vowel_streak(word: str) -> int
word str
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.

Approved · cc016-abs_206_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1