The Palindrome Number problem asks whether an integer x is a palindrome — reads the same forwards and backwards. Negative numbers are never palindromes. This easy problem tests integer manipulation without converting to a string, or string-based digit reversal. The math interview pattern is the core.
J.P. Morgan, Apple, Microsoft, Meta, Amazon, Google, Bloomberg, and virtually every tech company ask this easy problem. It's one of the first problems candidates encounter. The string conversion approach is trivial; the follow-up (without using a string) requires integer digit reversal and comparison.
Reverse half the integer. To avoid overflow, reverse only the second half. While x > reversed_half: take the last digit (x % 10), add to reversed_half * 10. Divide x by 10. x is palindrome if x == reversed_half (even length) or x == reversed_half // 10 (odd length, middle digit in reversed_half).
x=12321. reverse until x ≤ reversed_half:
x=12331: similarly reverse: reversed_half=133, x=12. 12 ≠ 133//10=13. Return false.
x == reversed_half; for odd, x == reversed_half // 10.Palindrome Number tests two things: edge case awareness (negatives, trailing zeros) and integer manipulation. The "reverse half" technique avoids overflow and is O(log n). Always handle edge cases first: if x < 0 or (x % 10 == 0 and x != 0), return false. Practice this problem with the follow-up constraint "without converting to string" to demonstrate mathematical thinking over string shortcuts.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Ugly Number | Easy | Solve | |
| Add Two Integers | Easy | Solve | |
| Calculate Money in Leetcode Bank | Easy | Solve | |
| Perfect Number | Easy | Solve | |
| A Number After a Double Reversal | Easy | Solve |