DSA problem
Reverse a String
Given a string s, reverse it and return the reversed string.
String reversal is one of the most common building blocks in programming. The two-pointer approach works just like array reversal: swap characters at the start and end, then move inward. In languages where strings are immutable (Java, Python, JavaScript), you convert to an array of characters, reverse, and join back. Built-in helpers exist (StringBuilder.reverse() in Java, slicing [::-1] in Python, split('').reverse().join('') in JavaScript), but interviewers often want a manual implementation to demonstrate understanding. Reversing a string is also a sub-step in many other problems: checking palindromes, reversing words in a sentence, and certain encoding/decoding algorithms.
Examples
s = "hello""olleh"Constraints
- 1 <= s.length <= 10^5
3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.