JavaEasyNumbers10 min

Reverse the digits of an integer

Return the reversed integer, preserving its sign and discarding leading zeros. Follow the stated ordering and edge-case conventions exactly. Interviewers use this task to probe algorithm selection, invariants, and boundary handling.

Input

One signed integer n.

Output

Return the reversed integer, preserving its sign and discarding leading zeros.

Constraints

-2147483648 <= n <= 2147483647.

Example

Input

120

Output

21

Example 2 input

1000000000

Output

1

This example exercises trailing zero removal.

Public test cases (2)

  • Input

    120

    Expected output

    21
  • Input

    -450

    Expected output

    -54
Hints (2)
  1. Identify the state needed to avoid recomputing work for each element.
  2. Accumulate the final digit into a long and remove it from the input.

Target complexity: time O(d) · space O(1)

Your solution

Checking runner availability…

Reference solution

Sign in for solution
All Java programs