Reverse an array of characters in place. You must use only constant extra memory.
DSA Animator › DSA Revision › Strings › Reverse String
Remember: in-place reversal is two pointers swapping toward the middle. The same move appears inside many harder problems. The video solves Reverse String (LeetCode 344, Easy) with the Two Pointers pattern from the Strings topic, and you can replay every step in the interactive Reverse String animation.
Reverse an array of characters in place. You must use only constant extra memory.
h, e, l, l, o becomes o, l, l, e, h.
Copying the characters into a new array backwards uses O of n extra space. The problem asks you to work in place.
Put one pointer at each end. Swap the two characters, then move both pointers inward. Stop when they meet.
Swap h and o, giving o, e, l, l, h. Move inward and swap e and l, giving o, l, l, e, h. The pointers meet at the middle l, which stays where it is. The array is reversed.
In code, set left to 0 and right to the last index. While left is less than right, swap and move both pointers. Each character is touched once, so it's O of n time and O of 1 space.
Remember: in-place reversal is two pointers swapping toward the middle. The same move appears inside many harder problems.