All practice tasks

Coding (Algo)

Reverse an ASCII Line

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

What this task practices

Reverse an ASCII Line is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.