Maintained by Vikas Dulgunde, software engineer
You are given a string `s`. Build and return the string you get when its characters are read from the last position to the first.
Order is the only thing that changes. Every character that was present stays present, including spaces, punctuation, and repeated letters, and the length of the result equals the length of the input.
An empty string has nothing to flip, so it comes back unchanged, and a single character reads the same forwards and backwards. Casing is preserved exactly, so an uppercase letter stays uppercase in its new spot.
Reading h-e-l-l-o from the back gives o-l-l-e-h.
The space and the capital letters keep their characters but land in mirrored positions: the trailing 'd' becomes the first character and the leading 'A' becomes the last.
There are no characters to reorder, so the empty string maps to itself.
Visible test cases
If you could walk the string from its last index down to index 0 and collect each character, what would you have built?
Strings are awkward to mutate character by character in many languages. Convert to an array of characters first, do the work, then join back.
You do not need a second array. Swap the character at the left end with the one at the right end, then step both pointers inward until they meet.
Read the input from the final character to the first and append each one to a result you grow as you go.
Convert the string to a character array, then mirror it by swapping the outermost pair and moving inward until the pointers cross.