Show problems as
Classic problem #1839MediumStringSliding Window

Longest Substring Of All Vowels in Order

Real-world version: Longest Complete Call Stretch
Tracked in this browser only
Read Longest Substring Of All Vowels in Order on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A wetland recorder listens all night and tags every call it hears with one of five letters: a, e, i, o, u. The tags are written down in the order the calls arrived, giving the string calls.

The five tags have a fixed ranking, a then e then i then o then u. A stretch is a run of consecutive tags from the log. A stretch is complete when both of these hold:

  • all five tags appear in it at least once, and
  • reading it from left to right, no tag ever ranks lower than the tag before it (so each tag either repeats the previous one or ranks higher).

Return the number of calls in the longest complete stretch of calls. If the log holds no complete stretch, return 0.

Examples

Example 1

Input
calls = "aaeeiioouu"
Output
10

The tags arrive as the blocks `aa`, `ee`, `ii`, `oo`, `uu`. All five tags appear and no tag ranks below the tag before it, so the whole log of ten calls is one complete stretch.

Example 2

Input
calls = "uaeiouu"
Output
6

The last six tags read `a e i o u u`: all five tags appear and none ranks below its predecessor, so that stretch is complete and holds six calls. The opening `u` cannot belong to it, because the tag after it ranks lower.

Example 3

Input
calls = "aeio"
Output
0

No call is ever tagged `u`, so no stretch holds all five tags.

Constraints

  • 1 <= calls.length <= 5 * 10^5
  • Every character of calls is one of 'a', 'e', 'i', 'o', 'u'.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def longest_complete_stretch(calls: str) -> int:
Java
public int longestCompleteStretch(String calls)