dsa · easy

Length of Last Word

A word is a maximal run of non-space characters. Given s made of English letters and spaces, return the length of the last word. s always contains at least one word.

Arguments

Example

s = "Hello World"5.

s = " fly me to the moon "4.

Constraints

1 <= s.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
"Hello World"

Expected:
5

Example 2

Input:
"   fly me   to   the moon  "

Expected:
4

Open in the Dojo editor