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.word='uaaeeiouuea' → 8
The substring "aaeeiouu" walks through the vowels in order and contains all five, so its length is 8.
word='aeioaeiuo' → 0
The part "aeio" lacks u, "aeiu" lacks o, and "uo" breaks the order, so no substring qualifies.
word.length ≤ 5 · 10⁵word consists only of the letters a, e, i, o, uword='uaaeeiouuea'
8
Run checks the first 3 tests in your browser. Submit checks all 22 tests on the server, hidden ones included.