FastPrepReverse an Integer
Problems/Reverse an Integer

Reverse an Integer

Morgan Stanley logoMorgan Stanley● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Morgan Stanley phone screen for interns. We chose signed 32-bit inputs, how signs are handled, and the result on overflow.

Our version is about 90% the same as the reported question.

Reverse the decimal digits of the signed integer x. Preserve its sign and discard zeros that become leading zeros after reversal.

Return 0 if the reversed value is outside the signed 32-bit range [-2147483648, 2147483647]. The reverse of zero is zero.

For this exercise, 64-bit intermediate arithmetic is allowed.

Function

reverseInteger(x: int) → int

Examples

Example 1

x = 123return = 321

The decimal digits 1,2,3 become 3,2,1.

Example 2

x = -120return = -21

Reversing the magnitude 120 gives 021, whose integer value is 21. Restoring the negative sign gives -21.

Example 3

x = 1534236469return = 0

The reversed value would be 9646324351, which is greater than 2147483647. Return zero.

Constraints

  • For this exercise, assume -2147483648 <= x <= 2147483647.

More Morgan Stanley interview questions

  • Unique Grid PathsPHONE SCREEN · Seen Oct 2026
  • Second and Third Distinct Order ValuesPHONE SCREEN · Seen Jul 2024
  • Binary Tree Preorder TraversalPHONE SCREEN · Seen Jan 2024
  • Find a Target-Sum SubarrayPHONE SCREEN · Seen Jan 2024
  • Two SumPHONE SCREEN · Seen Jan 2024
  • Generate Strings of Length at Least ThreeONSITE INTERVIEW · Seen Sep 2026
  • Three-Resource 0/1 KnapsackOA · Seen Sep 2026
  • Maximum Concurrent ProcessesOA · ONSITE INTERVIEW · Seen Sep 2026
  • Kth Largest Array ElementONSITE INTERVIEW · Seen Jul 2026
  • Maximum Total of Nonadjacent RatingsOA · Seen Jul 2026

Similar questions at other companies

  • Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
  • Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
  • Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
  • Roman to IntegerKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Minimum Difference Between Two Clock TimesMicron Technology · PHONE SCREEN
  • Decimal Digits in OrderZoomInfo · PHONE SCREEN
  • Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
  • Integer to String Without Built-insHudson River Trading · PHONE SCREENHudson River Trading interview questions
  • Excel Sheet Column TitleUiPath · PHONE SCREEN

Interview reports that mention this question

  • Morgan Stanley Intern Tech Rounds: 5 Experiences (Part 2 of 5)

Morgan Stanley interview experiences

  • Morgan Stanley Apprenticeship and Tech Interviews: 6 Experiences
  • Morgan Stanley New Grad Technology Analyst: 2 Experiences
  • Morgan Stanley Intern Oldest Loops: 5 Experiences (Part 5 of 5)
  • Morgan Stanley Intern OOP Loops: 5 Experiences (Part 4 of 5)
  • Morgan Stanley Intern Earlier Loops: 5 Experiences (Part 3 of 5)
All Morgan Stanley interview questionsSee Morgan Stanley hiring insights
Saved
class Solution {
    public int reverseInteger(int x) {
        // Write your code here.
    }

}
Checking account…