java.lang.Object
g1801_1900.s1839_longest_substring_of_all_vowels_in_order.Solution

public class Solution extends Object
1839 - Longest Substring Of All Vowels in Order.<p>Medium</p> <p>A string is considered <strong>beautiful</strong> if it satisfies the following conditions:</p> <ul> <li>Each of the 5 English vowels (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'</code>) must appear <strong>at least once</strong> in it.</li> <li>The letters must be sorted in <strong>alphabetical order</strong> (i.e. all <code>'a'</code>s before <code>'e'</code>s, all <code>'e'</code>s before <code>'i'</code>s, etc.).</li> </ul> <p>For example, strings <code>&quot;aeiou&quot;</code> and <code>&quot;aaaaaaeiiiioou&quot;</code> are considered <strong>beautiful</strong> , but <code>&quot;uaeio&quot;</code>, <code>&quot;aeoiu&quot;</code>, and <code>&quot;aaaeeeooo&quot;</code> are <strong>not beautiful</strong>.</p> <p>Given a string <code>word</code> consisting of English vowels, return <em>the <strong>length of the longest beautiful substring</strong> of</em> <code>word</code><em>. If no such substring exists, return</em> <code>0</code>.</p> <p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> word = &ldquo;aeiaaioaaaaeiiiiouuuooaauuaeiu&rdquo;</p> <p><strong>Output:</strong> 13</p> <p><strong>Explanation:</strong> The longest beautiful substring in word is &ldquo;aaaaeiiiiouuu&rdquo; of length 13.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> word = &ldquo;aeeeiiiioooauuuaeiou&rdquo;</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> The longest beautiful substring in word is &ldquo;aeiou&rdquo; of length 5.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> word = &ldquo;a&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> There is no beautiful substring, so return 0.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= word.length <= 5 * 10<sup>5</sup></code></li> <li><code>word</code> consists of characters <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • longestBeautifulSubstring

      public int longestBeautifulSubstring(String word)