FastPrepReverse an Integer
Problems/Reverse an Integer

Reverse an Integer

Microsoft logoMicrosoft● EasyINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: 2026-07-17 — The source did not specify behavior when the reversed value overflows a signed 32-bit integer. This version returns 0. The judged core task matches the visible source at about 98%.

Reverse the decimal digits of an integer, positive or negative, without converting the integer to a string or using string manipulation.

Complete reverse(int x). Preserve the sign, discard leading zeros in the reversed digits, and return 0 if the reversed value falls outside the signed 32 bit integer range.

Function

reverse(x: int) → int

Examples

Example 1

x = 123return = 321

The reversed integer is 321. Since the reversed integer is within the signed 32-bit integer range, it is the return value.

Example 2

x = 120return = 21

The reversed integer is 21. Notice that the leading zero in the input integer is not present in the reversed integer.

Example 3

x = -120return = -21

The reversed integer is -21. The negative sign is preserved during the reversal.

Constraints

  • -2^31 <= x <= 2^31 - 1

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int reverse(int x) {
      // write your code here
    }

}
Checking account…