Easy · Math

Reverse Number

Given a signed 64-bit integer n, reverse its decimal digits while keeping its sign. Leading zeros of the reversal disappear (1200 → 21 and −507 → −705). Return 0 if the reversed value does not fit in a signed 64-bit integer.

Examples

Example 1

n = 1234

Output: 4321

Example 2

n = -507

Output: -705

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Math problems