Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only.
Example 1
Input: s = Hello World
Output: 5
Explanation: The last word is "World", which has 5 letters.
Example 2
Input: s = fly me to the moon
Output: 4
Explanation: Trailing spaces are ignored, so the last word is "moon", which has 4 letters.
Example 3
Input: s = luffy is still joyboy
Output: 6
Explanation: The last word is "joyboy", which has 6 letters.
Walk backward from the end of the string. Skip any trailing spaces, then count characters until you hit the next space or the start — that count is the last word's length.
Run checks all cases above. Submit evaluates all test cases.