Reverse String Recursively

Easy~10 min

Given a string s, return the string reversed using recursion.

You must solve this problem recursively — do not use any loops or built-in reverse functions.

For example, if the input is "hello", the output should be "olleh".

Examples

Example 1
Input: s = "hello"
Output: "olleh"
Explanation: The characters are reversed: h-e-l-l-o becomes o-l-l-e-h.
Example 2
Input: s = "a"
Output: "a"
Explanation: A single character is already its own reverse.
Example 3
Input: s = ""
Output: ""
Explanation: An empty string reversed is still an empty string.

Constraints

  • 0 <= s.length <= 10^4
  • s consists of printable ASCII characters.
  • You must use recursion (no loops or built-in reverse).
Code
Ctrl+EnterRun|Ctrl+⇧+EnterSubmit
Output

Run your code to see results

Use Cmd+Enter to run