Reverse a Number
Reverse a Number
Given a non-negative integer N, print the number formed by reversing its digits.
For example 12345 becomes 54321.
Leading zeros disappear in the reversed number: reversing 1200 gives 21, not 0021. A single digit reverses to itself.
The classic method uses N % 10 to pull off the last digit and N / 10 (integer division) to drop it.
A single line containing one integer N.
A single integer: the digits of N in reverse order.
0 <= N <= 10^9
12345
54321
The digits 1 2 3 4 5 read backwards are 5 4 3 2 1.
Submit runs your code against 5 test cases — the 1 shown above plus 4 hidden ones covering the awkward cases. Run sample just tries the first example, which is usually what you want while you are still working it out.