#344

Reverse String

Easy Two pointers

  1. Read
  2. Understand
  3. Hints
  4. Approach
  5. Solution
  6. Solved

?The problem

Reverse a char array in place without making a new array.

This is a short summary in our own words. Read the full statement and examples on LeetCode: open problem ↗

◎Understanding

Really asking: flip the order of characters without making a new array.

Why this works: swapping the two ends fixes two positions at once; move inward until the pointers meet.

Example: ['h','e','l','l','o']

swap 0,4 → o e l l hswap 1,3 → o l l e hl=2, r=2 → stop

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Looping over the whole array and swapping every pair twice, which puts everything back where it started.