Problem Brief
Reverse an Integer
INTERNOA
See Microsoft online assessment and hiring insights
Rever an integer (positive or negative) without turning the integer to a sring or using string manipulation 💪
Function Description
Complete the function reverse in the editor.
reverse has the following parameter:
int x: the integer to reverse
(˶˃⤙˂˶) Thanks a TON, Rachel 💖
1Example 1
Input
x = 123
Output
321
Explanation
The reversed integer is 321. Since the reversed integer is within the signed 32-bit integer range, it is the return value.
2Example 2
Input
x = 120
Output
21
Explanation
The reversed integer is 21. Notice that the leading zero in the input integer is not present in the reversed integer.
3Example 3
Input
x = -120
Output
-21
Explanation
The reversed integer is -21. The negative sign is preserved during the reversal.
Constraints
Limits and guarantees your solution can rely on.
-2^31 <= x <= 2^31 - 1