Problem
In an AIG PC Global Services mobile workflow, you need a utility function that reverses a string. Given a string s, return a new string with its characters in reverse order.
Formal Specification
- Input: A single string
s
- Output: A string containing the characters of
s in reverse order
- Function behavior: The function must return the reversed string and should handle empty strings, spaces, punctuation, and Unicode characters.
Examples
Example 1
- Input:
s = "AIG"
- Output:
"GIA"
- Explanation: The characters are returned in reverse order.
Example 2
- Input:
s = "claim note"
- Output:
"eton mialc"
- Explanation: Spaces are treated like any other character and are also reversed.
Example 3
- Input:
s = ""
- Output:
""
- Explanation: Reversing an empty string returns an empty string.
Constraints
0 <= len(s) <= 10^5
s may contain uppercase letters, lowercase letters, digits, spaces, punctuation, and Unicode characters
- Return a new reversed string in
O(n) time