← Back to challenges

Recursion: Find The Longest Word

PythonHardrecursionstringsarrays

Instructions

Write a recursive function that will return the longest word in a sentence. In cases where more than one word is found, return the first one.

Examples

find_longest("I will and ever will be gratefully and perpetually loving you Tesh!") ➞ "perpetually"

find_longest("A thing of beauty is a joy forever.") ➞ "forever"

find_longest("Forgetfulness is by all means powerless!") ➞ "forgetfulness"

find_longest("\"Strengths\" is the longest and most commonly used word that contains only a single vowel.") ➞ "strengths"

Notes

  • Special characters and symbols don't count as part of the word.
  • Return the longest word found in lowercase letters.
  • You are expected to solve this challenge via a recursive approach.
  • An iterative versions of this challenge can be found via these links (1 and 2).
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.