A weathered summit registry keeps a single line per climbing party: each climber's name is written as one unbroken run of letters, and names are separated by one or more spaces because the logbook's pages are ruled unevenly. Some lines even start or end with stray spaces from a shaky hand. Given one such registry line, report how many characters make up the very last name recorded on it.
A single line containing the registry entry S. S consists only of uppercase and lowercase English letters (A-Z, a-z) and space characters (' '). The line may begin with spaces, end with spaces, or contain multiple consecutive spaces between names, but it always contains at least one non-space character.
Print a single integer: the number of characters in the last maximal run of non-space characters in S.
S <= 10^4S contains only English letters and space charactersS contains at least one non-space characterExample 1
Input
ridge runner falcon
Expected
6
Explanation
After the leading spaces, the registry line lists three names: 'ridge', 'runner', and 'falcon', followed by trailing spaces. The last name is 'falcon', which has 6 letters, so the output is 6.
Example 2
Input
Everest
Expected
7
Explanation
The line contains a single name with no spaces at all: 'Everest'. Since there is only one name, it is also the last one, and it has 7 letters, so the output is 7.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →