Reverse String

Easy
String
Time Limit: 1000ms
Memory Limit: 128MB
Problem Description

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.

Constraints
  • Do not allocate extra space for another array
  • You must do this by modifying the input array in-place with O(1) extra memory
  • 1 <= s.length <= 10^5
  • s[i] is a printable ASCII character
Input
{"s": "hello"}
Output
["o","l","l","e","h"]
Loading...
Available Test Cases:5 test cases
Test Case 1Sample
Input: {"s": "hello"}
Expected Output: ["o","l","l","e","h"]
Test Case 2Sample
Input: {"s": "Hannah"}
Expected Output: ["h","a","n","n","a","H"]
⚠️ Hidden test case
Test Case 3Sample
Input: {"s": "a"}
Expected Output: ["a"]
⚠️ Hidden test case
Test Case 4Sample
Input: {"s": "abcdef"}
Expected Output: ["f","e","d","c","b","a"]
⚠️ Hidden test case
Test Case 5Sample
Input: {"s": "racecar"}
Expected Output: ["r","a","c","e","c","a","r"]
⚠️ Hidden test case