X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Length of Last word
Basic Accuracy: 43.53% Submissions: 632 Points: 1

Given a string S consisting of upper/lower-case alphabets and empty space characters ‘ ‘. The string may contain spaces at the end. You will have return the length of last word which consists of alphabets only.

Example 1:

Input:
S = "Geeks for Geeks"
Output: 5
Explanation: The last word is "Geeks" 
             of length 5.

Example 2:

Input:
S = "Start Coding Here "
Output: 4
Explanation: The last word is "Here" of
             length 4.

Your Task:
You don't need to read input or print anything.Your task is to complete the function findLength() which takes a single argument(string S) and returns the length of last word of the string.

Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).

Constraints:
1<=|S|<=100

|S| denotes the length of the string S.

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Length of Last word

Output Window