Archaeologists recovered a machine that prints one lowercase rune every tick onto a tape. The machine is said to be running "in harmony" during any stretch where each printed rune is exactly the next letter of the alphabet after the previous one (so a run reading ...b, c, d... is harmonic, but z is never followed by a — the alphabet does not wrap for this machine).
Given the full tape as a string, find the length of its longest harmonic streak — the longest contiguous stretch of runes where every rune is the successor of the one immediately before it. A streak of a single rune (length 1) is always harmonic by itself.
A single line containing the tape s, made only of lowercase English letters.
Print a single integer: the length of the longest harmonic streak in s.
s consists only of lowercase English letters ('a'-'z').Example 1
Input
abacaba
Expected
2
Explanation
Scanning the tape: a→b is a successor pair (streak length 2), then b→a breaks it (reset to 1), a→c is not a successor pair (reset to 1), c→a breaks (reset to 1), a→b is a successor pair (streak length 2), b→a breaks (reset to 1). The longest streak seen is length 2.
Example 2
Input
abcde
Expected
5
Explanation
Every consecutive pair is a successor pair (a→b→c→d→e), so the entire tape is one harmonic streak of length 5.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →