#C3722. Longest Alphabetical Substring

    ID: 47181 Type: Default 1000ms 256MiB

Longest Alphabetical Substring

Longest Alphabetical Substring

Given a string s, find the length of the longest contiguous substring where the characters are in strictly increasing alphabetical order. A substring is defined as any continuous segment of the string. Formally, for a substring s[i..j] (with 0 ≤ i ≤ j < n), it is considered in alphabetic order if for each k from i+1 to j, the condition
\( s[k] > s[k-1] \) holds.

For example:

  • For s = "abcaacd", the longest alphabetically ordered substring is "abc" with a length of 3.
  • For s = "abcdefg", the entire string is in alphabetical order with a length of 7.
  • For an empty string, the answer is 0.

Your task is to implement a solution that reads the input string from standard input and prints the length of the longest alphabetical substring to standard output.

inputFormat

The input consists of a single line containing a string s. The string may include both lowercase and uppercase letters. It may also be empty.

Example:

abcaacd

outputFormat

Output a single integer representing the length of the longest contiguous substring of s that is in strictly increasing alphabetical order.

Example:

3
## sample
abcaacd
3