#1839

Longest Substring Of All Vowels in Order

specialist · 845 · lc medium +31 · premium · verified · 51.6% accepted · 851 likes · top 41%

Description

A string of English vowels is considered beautiful when:

- It includes each of the 5 vowels ('a', 'e', 'i', 'o', 'u') at least once.

- Its characters appear in non-decreasing alphabetical order.

For example, "aeiou" and "aaaeiiiioou" are beautiful, but "uaeio" and "aeoiu" are not.

Given a string word composed entirely of vowels, return the length of the longest beautiful substring, or 0 if there is none.

Example 1:

Input: word = "aeiaaioaaaaeiiiiouuuooaauuaeiu"
Output: 13
Explanation: The longest beautiful substring in word is "aaaaeiiiiouuu" of length 13.

Example 2:

Input: word = "aeeeiiiioooauuuaeiou"
Output: 5
Explanation: The longest beautiful substring in word is "aeiou" of length 5.

Example 3:

Input: word = "a"
Output: 0
Explanation: There is no beautiful substring, so return 0.

Code

1
2
3