Ctrl K

Vowel Ladder

Medium
The string word consists only of the vowels a, e, i, o, u. Call a string a ladder when: - all five vowels appear in it, each at least once; - the letters come in alphabetical order: all the as first, then all the es, then i, o and finally u. For instance, aeiou and aaeiiioouu are ladders, while aeiu (no o) and aeoiu (out of order) are not. Return the length of the longest substring of word that is a ladder, or 0 if there is none. A substring is a contiguous piece of the string.
Example 1
word='uaaeeiouuea' → 8

The substring "aaeeiouu" walks through the vowels in order and contains all five, so its length is 8.

Example 2
word='aeioaeiuo' → 0

The part "aeio" lacks u, "aeiu" lacks o, and "uo" breaks the order, so no substring qualifies.

Constraints
  • 1 ≤ word.length ≤ 5 · 10⁵
  • word consists only of the letters a, e, i, o, u
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLongest Repeat-Free Stretch MediumTwo-Letter Stretch MediumRecurring Gene Windows MediumWindow with Few Kinds of Letters MediumEvery Letter at Least k Times Medium
loading Python…
Input
word='uaaeeiouuea'
Expected
8

Run checks the first 3 tests in your browser. Submit checks all 22 tests on the server, hidden ones included.