JavaScriptEasyStrings10 min
Check a palindrome string
Return whether the string reads identically in both directions; comparison is case-sensitive and includes spaces. All input is valid JSON satisfying the constraints; do not mutate the meaning of values through type coercion. Interviewers use this problem to assess compare symmetric positions using two pointers.
Input
A JSON string on stdin.
Output
Print one compact JSON value: a boolean.
Constraints
0 <= string length <= 10000; ASCII characters only.
Example
Input
"level"
Output
true
Example 2 input
"a a"
Output
true
Boundary case: The empty string is a palindrome
Public test cases (2)
Input
"level"
Expected output
true
Input
"hello"
Expected output
false
Hints (2)
- Compare the first and last remaining characters
- The empty string is a palindrome
Target complexity: time O(n) · space O(1)
