You are given a string s. Your task is to reverse the string using recursion only and return the reversed string. You are not allowed to use loops or built-in reverse functions.
Example 1
Input: s = "hello"
Output: "olleh"
Explanation: The string is reversed using recursion.
Example 2
Input: s = "abcd"
Output: "dcba"
Explanation: The characters appear in reverse order.
Example 3
Input: s = "z"
Output: "z"
Explanation: A single character remains the same after reversing.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
hello
olleh
world
dlrow