Algorithms

Reverse String

easyalgorithmsstringtwo-pointers
0:00

Problem

Write a function that reverses a string. The input is given as an array of characters. Modify the array in-place and return the reversed array.

Your solution
Test results
Click Run tests to check your solution against the test cases.

About this challenge

Reverse String is a easy algorithms coding challenge. It tests algorithmic thinking and complexity analysis — the kind of problem-solving that shows up constantly in technical interviews. Write your solution in the editor above, run it against the test cases, and get instant feedback — free, in your browser, no sign-up.

Show a hint & approach (spoiler)

Hint: Use two pointers — one at the start, one at the end — and swap until they meet in the middle.

Approach: Two-pointer swap is O(n/2) = O(n) time with O(1) space. Avoid .reverse() to learn the pattern.

Keep practicing

Browse all coding challenges, or build intuition for the underlying concepts with the algorithm visualizers and the developer cheatsheets.