
In an OpenAI chat surface, some validation checks may need to determine whether a user-provided string reads the same forward and backward. Write a function that returns True if a string is a palindrome and False otherwise.
A palindrome is a string that is identical when reversed. For this problem, compare characters exactly as given: do not ignore spaces, punctuation, or letter casing.
ss is a palindromeExample 1
s = "racecar"TrueExample 2
s = "openai"FalseExample 3
s = "Aa"False"A" != "a".0 <= len(s) <= 10^5s contains printable ASCII charactersA solution with two pointers is expected and should run in linear time.
s = "racecar"OutputTrueWhyEach mirrored pair matches: `r-r`, `a-a`, `c-c`, with `e` in the center.s = "openai"OutputFalseWhyThe first and last characters do not match, so the string cannot be a palindrome.s = "abba"OutputTrueWhyThe outer and inner character pairs are equal, so the string reads the same both ways.0 <= len(s) <= 10^5s contains printable ASCII charactersComparison is exact: do not ignore spaces, punctuation, or casedef is_palindrome(s):