Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Reverse A String

Easy Acceptance 48% Points 20

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.

Examples
Example 1

Example 1

Input: s = "hello"

Output: "olleh"

Explanation: The string is reversed using recursion.

Example 2

Example 2

Input: s = "abcd"

Output: "dcba"

Explanation: The characters appear in reverse order.

Example 3

Example 3

Input: s = "z"

Output: "z"

Explanation: A single character remains the same after reversing.

Constraints
  • 1 = length of s = 105
  • The string contains printable characters only
Topics
Recursion
Companies
Visa Wayfair Mastercard
Added 19 Jul 2026 48% acceptance
Ln 1, Col 1Sign in to save your code
hello
olleh