Reverse String

easy

Reverse array of characters in-place using two pointers

Reverse String

Key Insight

Swap left and right elements, move both pointers inward until they meet

Step 1Initial Array
left
h
0
e
1
l
2
l
3
right
o
4
converge

Place pointers at both ends of the character array.

1 / 5

Learn the Pattern

Practice the Code

Step-by-Step Walkthrough: Reverse String

Swap left and right elements, move both pointers inward until they meet

  1. Initial Array

    Place pointers at both ends of the character array.

  2. First Swap

    Swap "h" and "o".

  3. Move & Swap

    Move pointers, swap "e" and "l".

  4. Pointers Meet

    Pointers cross - we're done!

  5. Reversed!

    "hello" → "olleh"