Reverse the Characters of an ASCII String

Quick Overview

A warm-up coding task that asks for the characters of a printable ASCII string in reverse order, with spaces and punctuation moved like any other character. It checks basic index handling and edge cases such as the empty string and very long inputs.

Reverse the Characters of an ASCII String

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Write a function that returns a string with its characters in reverse order. The report names this warm-up only as reversing a string. This version fixes the input to printable ASCII, so that reversing characters and reversing bytes give the same result, and asks for the reversed string as the return value. ### Function Signature ```python def reverse_string(s: str) -> str: ``` ### Rules - Return a string of the same length whose character at index `i` is `s[len(s) - 1 - i]`. - Every character moves, including spaces and punctuation; nothing is trimmed, collapsed or changed in case. - An empty input returns an empty string. ### Constraints - `0 <= len(s) <= 10^5` - `s` contains only printable ASCII characters (codes 32 to 126). ### Examples **Example 1** ```text Input: s = "firmware" Output: "erawmrif" ``` **Example 2** ```text Input: s = "a b!" Output: "!b a" ``` The space and the exclamation mark move like any other character. **Example 3** ```text Input: s = "" Output: "" ```

Overview: A warm-up coding task that asks for the characters of a printable ASCII string in reverse order, with spaces and punctuation moved like any other character. It checks basic index handling and edge cases such as the empty string and very long inputs.

Amazon logo
Amazon
Oct 31, 2026
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
0
0

Write a function that returns a string with its characters in reverse order.

The report names this warm-up only as reversing a string. This version fixes the input to printable ASCII, so that reversing characters and reversing bytes give the same result, and asks for the reversed string as the return value.

Function Signature

def reverse_string(s: str) -> str:

Rules

  • Return a string of the same length whose character at index i is s[len(s) - 1 - i] .
  • Every character moves, including spaces and punctuation; nothing is trimmed, collapsed or changed in case.
  • An empty input returns an empty string.

Constraints

  • 0 <= len(s) <= 10^5
  • s contains only printable ASCII characters (codes 32 to 126).

Examples

Example 1

Input:  s = "firmware"
Output: "erawmrif"

Example 2

Input:  s = "a b!"
Output: "!b a"

The space and the exclamation mark move like any other character.

Example 3

Input:  s = ""
Output: ""