Length of the Longest Alphabetical Continuous Substring - Problem
An alphabetical continuous string is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string "abcdefghijklmnopqrstuvwxyz".
For example, "abc" is an alphabetical continuous string, while "acb" and "za" are not.
Given a string s consisting of lowercase letters only, return the length of the longest alphabetical continuous substring.
Input & Output
Example 1 — Basic Continuous Sequence
$
Input:
s = "abacabad"
›
Output:
2
💡 Note:
The longest alphabetical continuous substring is "ab" which has length 2
Example 2 — Multiple Sequences
$
Input:
s = "abcde"
›
Output:
5
💡 Note:
The entire string "abcde" is alphabetically continuous with length 5
Example 3 — Single Character
$
Input:
s = "a"
›
Output:
1
💡 Note:
Single character strings have alphabetical continuous length of 1
Constraints
- 1 ≤ s.length ≤ 105
- s consists of only lowercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input String
String with mixed alphabetical sequences
2
Find Sequences
Identify consecutive alphabet letter groups
3
Return Length
Length of the longest continuous sequence
Key Takeaway
🎯 Key Insight: Track current sequence length, reset when alphabetical continuity breaks
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code