DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Two Pointer

Reverse String

**Problem Statement:** 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. **Hint / Expected Approach:** In-place swap with two pointers **Edge Cases to Consider:** - (1) Empty array - (2) Single character - (3) Even vs odd length

Examples

Example 1
Input: ['h','e','l','l','o']
Output: ['o','l','l','e','h']
Example 2
Input: ['H','a','n','n','a','h']
Output: ['h','a','n','n','a','H']
Example 3
Input: ['a']
Output: ['a']

Constraints

  • ▪1 <= data.length <= 10^5
  • ▪Memory complexity must be O(1) or O(k)
  • ▪Ensure non-overlapping pointer access

Watch Out For Edge Cases

  • ▪Empty array
  • ▪Single character
  • ▪Even vs odd length
Frequently Asked At
AmazonMicrosoftGoogleTCSWiproInfosys