Palindrome Check
Medium · rating 1100 · strings
Read a single line. Print YES if it reads the same forwards and backwards, otherwise NO.
Editorial
Palindrome Check tests whether a string reads the same forwards and backwards, character for character. Compare it to its reverse, or use two pointers converging from both ends.
print('YES' if s == s[::-1] else 'NO')Complexity
Time: O(n). Space: O(1) with the two-pointer version. (Unlike Valid Palindrome, this checks the raw string without ignoring case or punctuation.)