Reverse String
Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory.
Reverse String

Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory.

Example 1:
Input: ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]
Input
arr =["h","e","l","l","o"]

Initialize two pointers: left=0, right=4

Character Array
'h'
'e'
'l'
'l'
'o'
0
1
2
3
4

left = 0

right = 4

LRswap

Two Pointer Approach:

  1. Initialize left=0, right=n-1
  2. While left < right: swap s[left] and s[right]
  3. Move left++, right--
Left Pointer
Right Pointer
Swapped
Variables
No variables to display
DepthFunction Call
Stack empty
0/4