Ctrl K

Surviving a Double Flip

Easy
To reverse a number, write its digits in the opposite order. Any leading zeros are dropped: 5200 becomes 25, and 13 becomes 31. You are given a non-negative integer n. Reverse it, then reverse the result once more. Return true if you end up with n again, and false otherwise.
Example 1
n=4071 → True

4071 → 1704 → 4071: the number comes back to itself.

Example 2
n=350 → False

350 → 53 (the leading zero is dropped) → 35, which is not 350.

Example 3
n=0 → True

Zero stays zero when reversed.

Constraints
  • 0 ≤ n ≤ 10¹²
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Number That Reads Both Ways EasyValue of a Roman Numeral EasyAdd One to a Digit Array EasySum of Binary Strings EasyWhole Square Root Easy
loading Python…
Input
n=4071
Expected
True

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