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,
- Remove the first character.
- Reverse the remaining string.
- Add the first character above to the reversed string.
- Return the new string.