Rever an integer (positive or negative) without turning the integer to a sring or using string manipulation 💪
Complete the function reverse in the editor.
reverse has the following parameter:
int x: the integer to reverse
(˶˃⤙˂˶) Thanks a TON, Rachel 💖
Examples
01 · Example 1
x = 123 return = 321
The reversed integer is 321. Since the reversed integer is within the signed 32-bit integer range, it is the return value.
02 · Example 2
x = 120 return = 21
The reversed integer is 21. Notice that the leading zero in the input integer is not present in the reversed integer.
03 · Example 3
x = -120 return = -21
The reversed integer is -21. The negative sign is preserved during the reversal.
Constraints
-2^31 <= x <= 2^31 - 1
More Microsoft problems
- Rank Open BusinessesPHONE SCREEN · Seen May 2026
- Retain Top K ValuesPHONE SCREEN · Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW · Seen May 2026
- Order Records by Matching Start and EndONSITE INTERVIEW · Seen May 2026
- Recover Corrupted Master PageONSITE INTERVIEW · Seen Feb 2026
- Distinct Number Line MovesOA · Seen Oct 2025
- Get Minimum TimeSeen Jun 2025
- Count Subarrays with Bitwise OR PresentSeen Jun 2025
public int reverse(int x) {
// write your code here
}
x123
expected321
sign in to submit