Problem
At Notion, a text utility needs a function that reverses a string. Given a string s, return a new string with the characters of s in reverse order.
Formal Specification
- Input: A string
s
- Output: A string containing the same characters as
s, but in reverse order
- Function behavior: The function should not modify the original string in place; it should return the reversed result
Examples
Example 1
- Input:
s = "hello"
- Output:
"olleh"
- Explanation: The characters
h, e, l, l, o are returned in reverse order.
Example 2
- Input:
s = "Python"
- Output:
"nohtyP"
- Explanation: The first character becomes the last, and the last becomes the first.
Example 3
- Input:
s = "a b!"
- Output:
"!b a"
- Explanation: Spaces and punctuation are treated like any other character and are also reversed.
Constraints
0 <= len(s) <= 10^5
s may contain letters, digits, spaces, and symbols
- Return a new reversed string