VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-display-number-characters-longest-word-sentence/

⇱ Program for length of the longest word in a sentence - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program for length of the longest word in a sentence

Last Updated : 15 Sep, 2024

Given a string, we have to find the longest word in the input string and then calculate the number of characters in this word.

Examples:

Input : A computer science portal for geeks
Output : Longest word's length = 8

Input : I am an intern at geeksforgeeks
Output : Longest word's length = 13

The idea is simple, we traverse the given string. If we find end of word, we compare length of ended word with result. Else, we increment length of current word.


Output
13

Another Approach:


Output
13
Comment
Article Tags:
Article Tags: