
Given an array of characters chars, reverse the array in place and return it. The reversed result must contain the same characters in opposite order, and the solution should use constant extra space aside from the input array.
Example 1:
Input: chars = ["h", "e", "l", "l", "o"]
Output: ["o", "l", "l", "e", "h"]
Explanation: The characters are reversed by swapping from both ends toward the center.
Example 2:
Input: chars = ["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(chars) <= 10^5chars[i] is a single characterO(1) extra space beyond the input arraychars = ["h", "e", "l", "l", "o"]Output["o", "l", "l", "e", "h"]WhySwapping symmetric positions reverses the array.chars = ["H", "a", "n", "n", "a", "h"]Output["h", "a", "n", "n", "a", "H"]WhyThe first and last characters swap, then the second and second-last, and so on.1 <= len(chars) <= 10^5chars[i] is a single characterUse O(1) extra space beyond the input arraydef reverse_string(chars):