#K76887. Length of Last Word
Length of Last Word
Length of Last Word
Given a string s representing a sentence, your task is to find the length of its last word.
A word is defined as a maximal substring consisting of non-space characters. If there is no word in the string, output 0
.
Note: The input may contain leading or trailing spaces.
For instance, if the input is "Hello World", then the last word is "World" which has a length of 5.
Mathematically, if the sentence is given as a sequence of characters \( s_1 s_2 \ldots s_n \), then let the word boundaries be defined by spaces. The answer is the length of the last segment of consecutive non-space characters.
inputFormat
The input consists of a single line containing the string s.
The string may include multiple spaces and can have leading or trailing spaces.
outputFormat
Output a single integer representing the length of the last word in the input string.
## sampleHello World
5