consider a string sentence in word seperated by spaces where which substituting constituting of English alphabets only. find the first word in sentence
Answers
Answer:
Find the first maximum length even word from a string
Given a string of words separated by spaces. The task is to find the first maximum length even word from the string. Eg: “You are given an array of n numbers” The answer would be “an” and not “of” because “an” comes before “of”.
Examples:
Input: "this is a test string"
Output: string
Even length words are this, is, test, string. Even
maximum length word is string.
Input: "geeksforgeeks is a platform for geeks"
Output: platform
Only even length word is platform.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Answer:
When a string sentence is given as input, the first maximum even string is given as output.
Explanation:
Let the example string sentence be “I am a Student of ABC school”.
Here, in the above sentence, the even strings (that is, the word with even number of alphabets) are as follows.
- am – number of alphabets is two.
- of – number of alphabets is two.
- school – number of alphabets is six.
Since, the string “School” has even number and maximum number of alphabets, output is given as “school”.
That is when,
Input : “I am a Student of ABC school”
Output : “school”
Thus, first lengthy even string is given as output.