FunctionRacerProblemsRace

Longest Complete Vowel Stretch

MediumTwo pointersPython, JavaScript, TypeScript, Java, C++

s holds only the five vowels a, e, i, o and u. A stretch of consecutive letters is complete when it contains every one of the five vowels at least once and its letters never go backwards in the alphabet: reading it from left to right, all of its as come first, then its es, then its is, then its os, then its us.

Return the length of the longest complete stretch, or 0 if s has none. Letters may repeat any number of times inside a stretch.

Example 1

s "aeiaaioaaaaeiiiiouuuooaauuaeiu"
returns 13

The stretch aaaaeiiiiouuu (positions 7 to 19) has all five vowels in order and is the longest such stretch.

Example 2

s "aeeeoouuaaaeeoouu"
returns 0

The letters are in order but there is no i, so no stretch is complete.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems