Longest Substring Of All Vowels in Order
Real-world version: Longest Complete Call StretchThe 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.
def longest_complete_stretch(calls: str) -> int:public int longestCompleteStretch(String calls)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 14 test cases: 14 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Maximum Length Substring With Two OccurrencesReal-world version: Longest Twice-Only StretchEasy
- Substrings of Size Three with Distinct CharactersReal-world version: Three Clean Pigment WindowsEasy
- Longest Nice SubstringReal-world version: Longest Matched-Case RunEasy
- Longest Substring Without Repeating CharactersReal-world version: Largest Clean Tap BlockMedium