Character order · Easy
A text utility reverses the characters of one ASCII line. Spaces at either edge, punctuation and letter case are part of the content. The supplied input adapter removes a trailing line ending only; trimming the content would silently lose data.
Return the same ASCII characters in reverse order preserving every space and punctuation character.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ text: string }
Fields
- text is one printable ASCII line with character codes 32..126. It contains no carriage return or newline.
- The provided Java/C++ input adapter reads the complete line without stripping spaces. JS/Python receive the string directly.
Output
Return value
- Return a string of the same length with character i moved to position length-1-i.
- Empty input returns an empty string. Do not reverse words separately, lowercase text or trim it.
Constraints
- 0 <= text.length <= 200000. The input is ASCII only; Unicode grapheme reversal is outside scope.
- Do not print debug messages or add new characters to the returned content.
Examples
Example 1
{
"text": "API v1!"
}Returns
"!1v IPA"Example 2
{
"text": " hi "
}Returns
" ih "Required complexity
O(n) time and O(n) returned-output space