Problem
In AlphaSense, query text entered in search surfaces may need simple string transformations during client-side processing. Write a function that takes a string s and returns a new string with its characters in reverse order.
Formal Specification
- Input: a string
s
- Output: a string containing the characters of
s in reverse order
- Your function should preserve all characters exactly as they appear, including spaces, punctuation, digits, and letter casing.
Examples
Example 1
- Input:
s = "alphasense"
- Output:
"esnesahpla"
- Explanation: The characters are returned from last to first.
Example 2
- Input:
s = "AI 2024!"
- Output:
"!4202 IA"
- Explanation: Spaces and punctuation are reversed along with letters and digits.
Constraints
0 <= len(s) <= 10^5
s may contain uppercase letters, lowercase letters, digits, spaces, and punctuation
Notes
- Return the reversed string.
- Do not remove or modify any characters.
- Aim for a linear-time solution.
- In Python, strings are immutable, so an efficient solution typically converts the string to a list, swaps characters with two pointers, and joins the result.