Ctrl K

A Number That Reads Both Ways

Easy
You are given an integer num. Return True if its decimal notation reads the same left to right and right to left, and False otherwise. A minus sign counts as part of the notation. Bonus: can you do it without turning the number into a string?
Example 1
num=45654 → True

The digits 4, 5, 6, 5, 4 are the same in both directions.

Example 2
num=-77 → False

Right to left it reads "77-", which is not the same as "-77".

Example 3
num=320 → False

Backwards it reads "023", which differs from "320".

Constraints
  • -2³¹ ≤ num ≤ 2³¹ - 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyAdd One to a Digit Array EasySum of Binary Strings EasyWhole Square Root EasyPaving a Garden Path Easy
loading Python…
Input
num=45654
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 40 tests on the server, hidden ones included.