Write a recursive function that reverses the input string

I’ll instead explain the recursive algorithm itself. Take the example “input” which should produce “tupni”. You can reverse the string recursively by

  • If the string is empty or a single character, return it unchanged.
  • Otherwise,
    1. Remove the first character.
    2. Reverse the remaining string.
    3. Add the first character above to the reversed string.
    4. Return the new string.

Leave a Comment