Search⌘ K
AI Features

Solution: Reverse String

Understand how to reverse a string in place by swapping characters using two pointers moving from the start and end toward the center. Learn an efficient O(n) time and O(1) space solution that modifies the original array directly without extra memory.

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