Mid/SeniorString

Length of the Longest Alphabetical Continuous Substring

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.

Example 1
Inputs = "abacaba"
Output2
There are 4 distinct continuous substrings: "a", "b", "c" and "ab"; "ab" is the longest continuous substring.
Example 2
Inputs = "abcde"
Output5
"abcde" is the longest continuous substring.

Constraints

  • 1 <= s.length <= 10^5
  • s consists of only English lowercase letters.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate