Question
If the word that you just found is longer than the current longest word, replace the current longest word with the new word. When your
When your loop ends, the remainder of the input string should contain a single "word". Perform one final comparison to see whether this last word is the longest of them all.
Finally, print the longest word that you found.
Remember that your output should ONLY contain the longest word (and nothing else).
Examples:
Input: This is a very long sentence
Output: sentence
Input: the rain in spain falls mainly on the plain
Output: mainly
Input: the cat in the hat
Output: the
Explanation: the maximum word length for this string is 3. As a result, the final output is just the first 3-character word (the initial "the").
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started