Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Length of Last Word

XPChallenge Points: 10
levelLevel: Easy

Given a string s containing words and spaces, return the length of the last word.

A word is defined as the longest sequence of non-space characters.

Example 1:

Input: s = "Wscube tech"

Output: 4

Explanation:

The last word is "tech", which has length 4.

Example 2:

Input: s = " upskilling bharat"

Output: 6

Explanation:

The last word is "bharat", which has length 6.

Example 3:

Input: s = " learn to code "

Output: 4

Explanation:

The last word is "code", which has length 4.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result