Search⌘ K
AI Features

Solution: Reverse String

Explore how to reverse a string represented as a character array by using the two-pointer approach. Learn to swap characters in place without extra space and understand the algorithm's time and space efficiency to improve your coding interview skills.

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) ...