Check Whether an Integer Is a Palindrome

Quick Overview

Decide whether a signed 32-bit integer reads the same forward and backward in base 10. It tests digit manipulation with division and modulo, edge cases such as negative numbers and trailing zeros, and awareness of integer overflow.

Check Whether an Integer Is a Palindrome

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given an integer `x`, return `True` if `x` is a palindrome, and `False` otherwise. An integer is a palindrome when it reads the same forward and backward. For example, `121` is a palindrome while `123` is not. ### Function Signature ```python def is_palindrome_number(x: int) -> bool: ``` ### Rules - Read `x` in base 10 with no leading zeros. A negative number is never a palindrome, because its minus sign appears only at the front. ### Constraints - `-2^31 <= x <= 2^31 - 1` ### Examples ```text Input: x = 121 Output: True ``` `121` reads as `121` from left to right and from right to left. ```text Input: x = -121 Output: False ``` From left to right it reads `-121`. From right to left it becomes `121-`, so it is not a palindrome. ```text Input: x = 10 Output: False ``` Read backward, `10` becomes `01`, which is a different digit string.

Overview: Decide whether a signed 32-bit integer reads the same forward and backward in base 10. It tests digit manipulation with division and modulo, edge cases such as negative numbers and trailing zeros, and awareness of integer overflow.

Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given an integer x, return True if x is a palindrome, and False otherwise.

An integer is a palindrome when it reads the same forward and backward. For example, 121 is a palindrome while 123 is not.

Function Signature

def is_palindrome_number(x: int) -> bool:

Rules

  • Read x in base 10 with no leading zeros. A negative number is never a palindrome, because its minus sign appears only at the front.

Constraints

  • -2^31 <= x <= 2^31 - 1

Examples

Input: x = 121
Output: True

121 reads as 121 from left to right and from right to left.

Input: x = -121
Output: False

From left to right it reads -121. From right to left it becomes 121-, so it is not a palindrome.

Input: x = 10
Output: False

Read backward, 10 becomes 01, which is a different digit string.