easy
strings
Return a new string containing the characters of s in reverse order. Preserve spaces, punctuation, casing, and repeated characters exactly.
Input / output
- Input:
s: string - Output: reversed string
Examples
"hello"returns"olleh"."Hello, World!"returns"!dlroW ,olleH".
Constraints
0 <= s.length <= 100,000- Treat the input as a sequence of characters; do not trim or normalize it.
Follow-up How would the solution change if the input were a mutable character array that must be reversed in place?
Examples
Example 1
Input: s = "hello"
Output: "olleh"
Example 2
Input: s = "Tesla"
Output: "alseT"
Example 3
Input: s = "12345"
Output: "54321"
🔒 7 hidden
Running will execute all 10 cases, including 7 hidden ones.