Digit Reversal and Palindrome Number Check

Medium ⏱ 12 min 63% acceptance ★★★★★ 4.8
Write a function is_palindrome_number(n) that returns True if the non-negative integer n reads the same forwards and backwards as a number, computed by reversing its digits with a while loop using arithmetic (% 10, // 10) — no string conversion.

Examples

Example 1
Input
is_palindrome_number(121)
Output
True
Explanation

Reversing 121 gives 121.

Example 2
Input
is_palindrome_number(123)
Output
False
Explanation

Reversing 123 gives 321, which differs.

Constraints

  • n is a non-negative integer.
  • Must not convert n to a string.

Topics

Loopswhile loop

Companies

UberPayPal

Hints

Hint 1

Build the reversed number digit by digit: `reversed_n = reversed_n * 10 + n % 10`.

Hint 2

Compare the fully reversed number to a saved copy of the original.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.