Find the Longest Ordered Run Containing Every Vowel
Quick Overview
Find the Longest Ordered Run Containing Every Vowel. word contains only the five lowercase vowels. Find the longest contiguous substring whose characters are nondecreasing alphabetically and which contains each of a, e, i, o, and u at least once.
Find the Longest Ordered Run Containing Every Vowel
Company: Rippling
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
`word` contains only the five lowercase vowels. Find the longest contiguous substring whose characters are nondecreasing alphabetically and which contains each of a, e, i, o, and u at least once. Return its length, or zero if none exists.
```cpp
class Solution {
public:
int longestBeautifulSubstring(string word);
};
```
### Examples
**Example 1:**
```text
word = "aaeeiioouu"
Output: 10
Explanation: The whole string contains every vowel in order.
```
**Example 2:**
```text
word = "uuaeioou"
Output: 6
Explanation: The suffix aeioou is valid; the leading u characters cannot precede a in an ordered substring.
```
### Constraints
- `1 <= word.length <= 5*10^5`.
- Every character is one of `a`, `e`, `i`, `o`, `u`.
### Clarifying Questions
Order is nondecreasing, so repetitions are permitted. All five vowels must occur; a sorted run omitting one vowel is insufficient.
```hint Inspect the structure
What must hold about order and vowel coverage inside a qualifying contiguous substring?
```
### Reasoning checkpoints
- Enforce contiguity, nondecreasing order, and presence of all five vowels.
- Prove that no longer qualifying substring exists, including runs that skip a required vowel.
### Optional extensions
How would you generalize the method to a specified ordered alphabet?
Overview: Find the Longest Ordered Run Containing Every Vowel. word contains only the five lowercase vowels. Find the longest contiguous substring whose characters are nondecreasing alphabetically and which contains each of a, e, i, o, and u at least once.
Find the Longest Ordered Run Containing Every Vowel
Rippling
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0
Problem
word contains only the five lowercase vowels. Find the longest contiguous substring whose characters are nondecreasing alphabetically and which contains each of a, e, i, o, and u at least once. Return its length, or zero if none exists.
class Solution {
public:
int longestBeautifulSubstring(string word);
};
Examples
Example 1:
word = "aaeeiioouu"
Output: 10
Explanation: The whole string contains every vowel in order.
Example 2:
word = "uuaeioou"
Output: 6
Explanation: The suffix aeioou is valid; the leading u characters cannot precede a in an ordered substring.
Constraints
1 <= word.length <= 5*10^5
.
Every character is one of
a
,
e
,
i
,
o
,
u
.
Clarifying Questions Guidance
Order is nondecreasing, so repetitions are permitted. All five vowels must occur; a sorted run omitting one vowel is insufficient.
Reasoning checkpoints
Enforce contiguity, nondecreasing order, and presence of all five vowels.
Prove that no longer qualifying substring exists, including runs that skip a required vowel.
Optional extensions
How would you generalize the method to a specified ordered alphabet?