1839. Longest Substring Of All Vowels in Order Medium

@problem@discussion
#String#Sliding Window



1/**
2 * [1839] Longest Substring Of All Vowels in Order
3 *
4 * A string is considered beautiful if it satisfies the following conditions:
5 * 
6 * 	Each of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it.
7 * 	The letters must be sorted in alphabetical order (i.e. all 'a's before 'e's, all 'e's before 'i's, etc.).
8 * 
9 * For example, strings "aeiou" and "aaaaaaeiiiioou" are considered beautiful, but "uaeio", "aeoiu", and "aaaeeeooo" are not beautiful.
10 * Given a string word consisting of English vowels, return the length of the longest beautiful substring of word. If no such substring exists, return 0.
11 * A substring is a contiguous sequence of characters in a string.
12 *  
13 * Example 1:
14 * 
15 * Input: word = "aeiaaio<u>aaaaeiiiiouuu</u>ooaauuaeiu"
16 * Output: 13
17 * Explanation: The longest beautiful substring in word is "aaaaeiiiiouuu" of length 13.
18 * Example 2:
19 * 
20 * Input: word = "aeeeiiiioooauuu<u>aeiou</u>"
21 * Output: 5
22 * Explanation: The longest beautiful substring in word is "aeiou" of length 5.
23 * 
24 * Example 3:
25 * 
26 * Input: word = "a"
27 * Output: 0
28 * Explanation: There is no beautiful substring, so return 0.
29 * 
30 *  
31 * Constraints:
32 * 
33 * 	1 <= word.length <= 5 * 10^5
34 * 	word consists of characters 'a', 'e', 'i', 'o', and 'u'.
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/longest-substring-of-all-vowels-in-order/
40// discuss: https://leetcode.com/problems/longest-substring-of-all-vowels-in-order/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn longest_beautiful_substring(word: String) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_1839() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.