JavaScriptEasyStrings10 min
Reverse a string
Reverse every character of the supplied ASCII string. All input is valid JSON satisfying the constraints; do not mutate the meaning of values through type coercion. Interviewers use this problem to assess reverse the character sequence without changing its contents.
Input
A JSON string on stdin.
Output
Print one compact JSON value: a string.
Constraints
0 <= string length <= 10000; ASCII characters only.
Example
Input
"hello"
Output
"olleh"
Example 2 input
"12!?"
Output
"?!21"
Boundary case: An empty string remains empty
Public test cases (2)
Input
"hello"
Expected output
"olleh"
Input
"a b"
Expected output
"b a"
Hints (2)
- Convert the string into characters
- An empty string remains empty
Target complexity: time O(n) · space O(n)
