Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Recursive String Reversal
00:00
5 left

Recursive String Reversal

EasyPython

Problem

Reverse a string using recursion.

Implement reverse_string(s) to return a new string containing the characters of s in reverse order. Use recursive calls as the primary technique, preserve spaces and special characters, and do not use Python's built-in reverse or slicing-based reversal.

Function: def reverse_string(s):

Input: a string. Output: its reversed string.

Constraints

  • 0 <= len(s) <= 1000
  • s may contain letters, digits, spaces, and special characters
  • The result must preserve every input character exactly once
  • Use recursion for the reversal logic
  • Do not use built-in reversal functions or slicing-based reversal

Function Signature

def reverse_string(s):
Interviewer

Your question is Recursive String Reversal. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.