This post is completed by 2 users

  • 0
Add to List
Beginner

331. Find Largest and Smallest word in a given String

Objective: Given a String, write a program to find the largest and smallest word in it.

Example:

Input String: test
Smallest Word: test
Largest Word: test
------------------
Input String: This problem is solved at the Algorithms tutorial horizon
Smallest Word: is
Largest Word: Algorithms

Approach:

Do a single traversal and keep track of the longest ad smallest words using word lengths.

See the code for more understanding, it is self-explanatory.

Output:

Input String: test
Smallest Word: test
Largest Word: test
------------------
Input String: This problem is solved at the Algorithms tutorial horizon
Smallest Word: is
Largest Word: Algorithms