Easy Text

Reverse String

Receives a string of text and returns its characters in reverse order. It uses the classic two-pointer technique: one pointer starts at the beginning, the other at the end, and on each step they swap the characters they point to, then move one position toward each other. This continues until the pointers meet (an odd-length string leaves its middle character untouched) or cross (an even-length string has every character swapped). The whole string is reversed in place in O(n) time using only two extra variables. Returns a new string with the characters in reverse order; an empty or single-character string is returned unchanged.

Visualization

Input

Algorithm code

Custom input

Saved inputs

References