
At Spotify, a text-processing utility stores strings as mutable character arrays. Write a function that reverses the array in place without allocating another array for the result.
Given a list of characters s, modify s so that its characters appear in reverse order.
s — a list of single-character stringss directly and return None.Example 1
Input: s = ["h", "e", "l", "l", "o"]
Output: ["o", "l", "l", "e", "h"]
Explanation: Swapping from both ends reverses the array in place.
Example 2
Input: s = ["H", "a", "n", "n", "a", "h"]
Output: ["h", "a", "n", "n", "a", "H"]
Explanation: The first and last characters are swapped, then the process continues inward.
1 <= len(s) <= 10^5s is a single printable characterO(1) extra spaces = ["h", "e", "l", "l", "o"]Output["o", "l", "l", "e", "h"]WhyCharacters are swapped from the ends toward the center.s = ["H", "a", "n", "n", "a", "h"]Output["h", "a", "n", "n", "a", "H"]WhyThe array is reversed in place without allocating another list.1 <= len(s) <= 10^5Each element of s is a single printable characterUse O(1) extra spaceModify the input list in placedef reverse_string(s):