150. Reverse a String

EasyStringString

Given a string s, return the string reversed.

You must reverse the string in-place if working with a character array, but for this problem simply return the reversed version of the input string.

Input: A single string s (may include spaces, digits, or special characters).

Output: A single string — the reverse of the input.

Examples

Example 1
Input: hello
Output: olleh
Explanation: Reading 'hello' from right to left gives 'o','l','l','e','h' → 'olleh'.
Example 2
Input: racecar
Output: racecar
Explanation: 'racecar' is a palindrome so reversing it gives the same string.
Example 3
Input: Hello World
Output: dlroW olleH
Explanation: Reverse every character including the space: 'Hello World' → 'dlroW olleH'.

Constraints

Asked by

HCLTechWiproBloombergAmazonMicrosoftGoogle
Solve this problem in the editor →