Reverse String

Easy
Concept
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Reverse String

Approach

Use two pointers starting at the beginning and end of the array. Swap the characters at both pointers, then move them inward until they meet. This reverses the array in-place without extra space.

Complexity Analysis

Time
O(n)
Space
O(1)

Pattern

Two Pointers (Converging)

Why It Works

Swapping from both ends ensures every character reaches its mirror position in exactly n/2 swaps.

Updated Feb 2026