Problems / Reverse String
Easy

Reverse String

Easy 0 submissions 10 coins +50 XP
String Two Pointers
Problem Description
## Problem Write a function that reverses a string. The input string is given as an array of characters `s`. You must do this by modifying the input array **in-place** with O(1) extra memory. Return the modified array after reversing. ## Examples **Example 1:** ``` Input: s = ["h","e","l","l","o"] Output: ['o', 'l', 'l', 'e', 'h'] ``` **Example 2:** ``` Input: s = ["H","a","n","n","a","h"] Output: ['h', 'a', 'n', 'n', 'a', 'H'] ``` ## Hints - Use the **two-pointer technique**. - Place one pointer at the start and another at the end, swap the characters, then move both pointers inward. - Stop when the two pointers meet in the middle.
Constraints
- `1 <= s.length <= 10^5` - `s[i]` is a printable ASCII character.

Need help?

Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.

Video Call Whiteboard Live Coding Screen Share