JavaEasyNumbers10 min
Check whether a number is a palindrome
Print true when the decimal representation reads identically in both directions; negative numbers are not palindromes. Follow the stated ordering and edge-case conventions exactly. Interviewers use this task to probe algorithm selection, invariants, and boundary handling.
Input
One integer n.
Output
Print true when the decimal representation reads identically in both directions; negative numbers are not palindromes.
Constraints
-2147483648 <= n <= 2147483647.
Example
Input
1221
Output
true
Example 2 input
1001
Output
true
This example exercises a further boundary or ordering case.
Public test cases (2)
Input
1221
Expected output
true
Input
123
Expected output
false
Hints (2)
- Identify the state needed to avoid recomputing work for each element.
- Reverse the digits using a long and compare with the original nonnegative value.
Target complexity: time O(d) · space O(1)
