Length of Last Word Problem
Length of Last Word Problem — ExecCode Easy DSA Practice
Solve the Length of Last Word problem on ExecCode. Free online easy DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a string s consisting of words and spaces, return the length of the last word in the string. Your task is to a word is a maximal substring consisting of non-space characters only. Return the required answer exactly as shown in the examples.
Examples
Input {"s": "Hello World"}; Output 5. Input {"s": " fly me to the moon "}; Output 4
Constraints
1 <= s.length <= 10^4 s consists of only English letters and spaces ' '. There will be at least one word in s.
Practice Length of Last Word free on ExecCode. Browse DSA problems, topic map, and placement guides.