Determine whether a string reads the same forward and backward when comparing characters by ASCII value.
Problem
Given a string, determine whether it is ASCII palindromic.
A string is ASCII palindromic if, for every position i, the character at i matches the character at the mirrored position from the end, when compared directly as characters.
In other words, the string must read the same from left to right and right to left.
Return whether the string satisfies this property.
Input Format
- A single string
s.
The string may contain letters, digits, spaces, or other printable characters unless otherwise stated by the platform.
Output Format
- Return
trueifsis ASCII palindromic. - Otherwise, return
false.
Constraints
- Compare characters directly; no normalization is required unless explicitly stated.
- The answer should be based on exact character matching.
- If the string is empty or has one character, it is palindromic by definition.
Example 1
Input
"racecar"
Output
true
Explanation
The string reads the same from left to right and right to left.
Example 2
Input
"hello"
Output
false
Explanation
The first and last characters differ, so the string is not palindromic.
Show 1 more example
Example 3
Input
"abba"
Output
true
Explanation
Characters match in mirrored positions: a=a and b=b.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.