{{title_post}}

{{title_tag}} | {{date}}

Problem Description:


s is a string that is our input. Words in s are separated by spaces. We have to print the length of the last word. If there is no word, then the output is 0. If there is a single word, then output is the length of that word.


Constraints:

  • \(1 \le s.length \le 10^4\)
  • s consists of only English letters and spaces ' '.


Ideological Analysis:

If there is no word then we have nothing to check. Otherwise, we have to indicate the last word. So, we can split the string by spaces and find the number of words! Then print the length of the last word!


Click here for Source Code.

{{post_author}}, {{date}}


Share this article on →