Reverse the Characters of an ASCII String
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
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.
Constraints
- 0 <= len(s) <= 10^5
- s contains only printable ASCII characters (codes 32 to 126)
Examples
Input: ('',)
Expected Output: ''
Explanation: Minimum valid: an empty string returns an empty string.
Input: ('Q',)
Expected Output: 'Q'
Explanation: Minimum valid: a single character returns itself.
Hints
- For each output position i, work out which input position supplies its character.
- Spaces, punctuation, quotes and backslashes are ordinary characters here: nothing is trimmed, collapsed or re-cased.
- Check your approach on lengths 0, 1, 2 and 3 before trusting it on longer strings.