Skills101
← All coding problems

Reverse String

easyStrings+10 XPTime limit 2s

Reverse a string in place — that is the interview version: swap the first and last characters, then the second and second-last, and so on, moving two pointers towards the middle.

Input: one line s (printable characters; it does not start or end with a space).

Output: s reversed.

Constraints: 1 ≤ length of s ≤ 10⁵.

Practise the technique: your language can probably reverse a string in one call — try writing the two-pointer swap loop yourself on an array of characters. That loop is the building block for many harder problems.

Sample input 1

hello

Sample output 1

olleh

Sample input 2

Hannah

Sample output 2

hannaH

📖 Stuck? Learn the pattern

Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).

Loading editor…

Log in to run and submit your code — it's free.