Menu
CoddyTech

Reverse the Digits

You get a non-negative integer n. Return the number you get by writing its decimal digits in reverse order. Zeros that end up in front are dropped, so 120 becomes 21.

Function

reverseDigits(n: integer) → integer
ninteger
the non-negative integer to reverse
Returnsinteger
the digits of n in reverse order, as a number

Constraints

  • 0 ≤ n < 109
  • The reversed number also fits in a signed 32-bit integer.

Examples

Input
n = 1234
Output
4321
Explanation
The digits of 1234 are 1, 2, 3 and 4. Read from the end they are 4, 3, 2 and 1, which is 4321.
challenge icon

Follow-up

If n could be any 32-bit integer, its reverse might not fit. How would you detect that before the multiplication overflows?

Reset code
def reverseDigits(n):
    # Write code here

Test #1

Test #2

Test #3

Argument

n = 1234

Expected Output

4321