
Given an array of characters chars, reverse the array in place and return it. The solution must modify the input array directly using O(1) extra space.
Example 1:
Input: chars = ["h", "e", "l", "l", "o"]
Output: ["o", "l", "l", "e", "h"]
Explanation: Swapping characters from both ends reverses the array.
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 printable characterchars = ["h", "e", "l", "l", "o"]Output["o", "l", "l", "e", "h"]WhySwapping the first and last characters, then the second and fourth, reverses the array.chars = ["H", "a", "n", "n", "a", "h"]Output["h", "a", "n", "n", "a", "H"]WhyThe characters are reversed by swapping matching positions from the ends toward the center.1 <= len(chars) <= 10^5chars[i] is a single printable characterThe reversal must be done in place using constant extra spacedef reverse_string(chars):