Search⌘ K
AI Features

Solution: Reverse String

Understand how to apply the two pointers technique to reverse a character array in-place for string reversal problems. This lesson helps you implement an efficient algorithm with O(n) time and constant space complexity by swapping characters from both ends toward the center.

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