You are given a string represented as an array of individual characters. Rearrange the characters so that the sequence reads from back to front, effectively flipping the order of every element.
The transformation must happen directly inside the given array. You are not allowed to allocate a second array to hold the result, so the work should be done using only a constant amount of extra space.
Example 1
Input: s = ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]
Each character trades place with its mirror position from the opposite end.
Example 2
Input: s = ["A","d","m","i","t"]
Output: ["t","i","m","d","A"]
The first and last characters swap, then the pair moving inward.
Constraints
1 <= s.length <= 10^5s[i] is a printable ASCII characterYou must modify the array in place with O(1) extra memorySee the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI