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.

lock icon+13 hidden tests on Submit

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 cases

Case 1

Case 2

Case 3

Input

n = 1234

Expected

4321