PythonEasyStrings10 min
Check whether a string is a palindrome
Compare characters exactly, including spaces and letter case. The empty string is a palindrome. Interviewers use this problem to assess move two pointers inward and stop on the first mismatch.
Input
One ASCII line.
Output
Print true or false in lowercase.
Constraints
0 <= length <= 100000.
Example
Input
racecar
Output
true
Example 2 input
a a
Output
true
Spaces participate in the comparison.
Public test cases (2)
Input
racecar
Expected output
true
Input
Python
Expected output
false
Hints (2)
- Identify the state needed to avoid repeated work.
- Move two pointers inward and stop on the first mismatch.
Target complexity: time O(n) · space O(1)
