Reverse a String - Coding Interview Problem
Last modified: April 6, 2023
Problem Description
Given a string s
, write a function reverse_string(s: str) -> str
to reverse the input string and return the reversed string as output.
Function Signature
def reverse_string(s: str) -> str:
Output
The reversed string of s
.
Example
assert reverse_string("hello") == "olleh" assert reverse_string("Tesla") == "alseT" assert reverse_string("12345") == "54321"
Example 1
Input: s = "hello"
Result: "olleh"
Example 2
Input: s = "Tesla"
Result: "alseT"
Example 3
Input: s = "12345"
Result: "54321"