
At Notion, a text utility needs a function that returns a string with its characters reversed. Given a string s, write a function that returns a new string containing the characters of s in reverse order.
ss reversedExample 1
s = "hello""olleh"Example 2
s = "Data 123""321 ataD"0 <= len(s) <= 10^5s may contain uppercase letters, lowercase letters, digits, spaces, punctuation, and Unicode charactersYou may assume the input is a valid string. Aim for a solution that runs in linear time. If you choose to build the result manually, avoid repeatedly concatenating immutable strings inside a loop, since that can be less efficient for large inputs.
s = "hello"Output"olleh"WhyReading the characters from the end to the beginning gives the reversed string.s = "Data 123"Output"321 ataD"WhyThe space is treated like any other character, so the entire sequence is reversed.s = "a"Output"a"WhyA single-character string is already the same when reversed.0 <= len(s) <= 10^5s consists of valid string characters, including spaces and punctuationReturn a new reversed stringdef reverse_string(s):