Reverse Integer
Updated
Problem statement
You are given a signed 32-bit integer x. Write the digits of x in the opposite order and return that number, keeping the sign of x. Zeros that end up at the front of the reversed number are dropped, so 1200 becomes 21.
If the reversed number is smaller than -2147483648 or larger than 2147483647, it does not fit in a signed 32-bit integer; return 0 instead.
Function
reverse(x: int) → intExamples
Example 1
x = 4096return = 6904The digits 4, 0, 9, 6 read backwards are 6, 9, 0, 4, so the answer is 6904.
Example 2
x = -5070return = -705Reverse the digits of 5070 to get 0705. The leading zero is dropped, giving 705, and the minus sign stays: -705.
Example 3
x = -2147483412return = -2143847412The digits of 2147483412 backwards are 2143847412. The result -2143847412 is still at least -2147483648, so it fits in a 32-bit integer and is returned.
Example 4
x = 1999999999return = 0Backwards the digits give 9999999991. That is larger than 2147483647, the largest 32-bit integer, so the answer is 0.
Constraints
-2147483648 <= x <= 2147483647(any signed 32-bit integer)
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions
- Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Logistic Regression with Gradient DescentYahoo · PHONE SCREENYahoo interview questions
- Evaluate an Arithmetic Expression Written in WordsBrex · PHONE SCREEN
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Integer to English Words in USD and INR StylesVeeam · PHONE SCREEN
- Adaptive Calibration ErrorOpenAI · PHONE SCREENOpenAI interview questions
- Sum of Smallest Non-DivisorsThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Square Root FunctionCitadel · PHONE SCREENCitadel interview questions
- Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)