
At Apple, a text-processing utility needs a function that reverses a string. Given a string s, return a new string with its characters in reverse order.
ss in reverse orderExample 1
Input: s = "swift"
Output: "tfiws"
Explanation: The characters are returned in reverse order.
Example 2
Input: s = "Hello, World!"
Output: "!dlroW ,olleH"
Explanation: Letters, punctuation, spaces, and symbols are all reversed as individual characters.
0 <= len(s) <= 10^5s may contain uppercase letters, lowercase letters, digits, spaces, and punctuationA correct solution should run in linear time with respect to the length of the string.
s = "swift"Output"tfiws"WhyThe characters `s`, `w`, `i`, `f`, `t` are reversed to `t`, `f`, `i`, `w`, `s`.s = "Hello, World!"Output"!dlroW ,olleH"WhyEvery character, including the comma, space, and exclamation mark, is reversed.s = "a"Output"a"WhyA single-character string is unchanged when reversed.0 <= len(s) <= 10^5s consists of printable characters, including letters, digits, spaces, and punctuationThe function should return a new reversed stringdef reverse_string(s):