Interview Questions/Coding/Alphabet Run Monitor

Alphabet Run Monitor

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Alphabet Run Monitor

A telemetry validator watches a lowercase character stream. A clean alphabet run is a contiguous substring where every next character is exactly one alphabet step after the previous character. For example, a can be followed by b, b can be followed by c, and so on. Runs stop as soon as the next character does not continue the immediate alphabet order. Input Format: You are given a lowercase string stream. Output Format: Return the length of the longest clean alphabet run in the stream.

Examples

Example 1
Input:
stream = "abacaba"
Output:
2

Explanation: The longest consecutive alphabet run is "ab". Its length is 2, so the output is 2.

Approach hint

Look for the state that actually matters after each operation.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp