Search⌘ K
AI Features

Solution: Reverse String

Understand how to reverse a string represented as a character array in-place by using two pointers starting from each end. Learn to swap characters while moving pointers inward until the string is fully reversed, achieving linear time with constant space.

Statement

You are given a character array, s, representing a string. Write a function that reverses the array in-place.

  • The reversal must be done by modifying the original array directly.

  • You cannot use extra memory beyond a constant amount O(1)O(1) ...