All problems
0790MediumStringSliding Window

Longest Complete Call Stretch

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1839Longest Substring Of All Vowels in Order

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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