#C7510. Longest Alphabetically Ordered Substring
Longest Alphabetically Ordered Substring
Longest Alphabetically Ordered Substring
You are given a sentence consisting of words separated by spaces. Your task is to determine the length of the longest contiguous substring (i.e., sequence of consecutive words) where the words are arranged in non-decreasing alphabetical order according to their first character.
In other words, if the words in the substring are \(w_1, w_2, \ldots, w_k\) and their first characters are \(a_1, a_2, \ldots, a_k\) respectively, then the substring is valid if it satisfies:
\( a_1 \le a_2 \le \ldots \le a_k \)
Your goal is to output the maximum \(k\) for which the condition holds.
inputFormat
Input will be given as a single line from stdin containing a sentence composed of words separated by spaces.
outputFormat
Output a single integer to stdout representing the length of the longest alphabetically ordered contiguous substring.## sample
apple banana cherry
3