Number Digits Backward
Updated
Problem statement
You are given an integer n. Write its digits in the opposite order and return the number you get.
- If
nis negative, the answer is negative too. Reverse the digits and keep the minus sign in front. - Zeros at the end of
nmove to the front when reversed, and a number does not keep zeros in front. For example,500becomes5. nfits in a 32-bit integer, but the answer may not. Return it as a 64-bit integer.
Function
reverseDigits(n: int) → longExamples
Example 1
n = 123return = 321The digits 1, 2, 3 in reverse order are 3, 2, 1, so the answer is 321.
Example 2
n = -4050return = -504Reverse the digits of 4050 to get 0, 5, 0, 4, which is the number 504. The zero in front is dropped. The minus sign stays, so the answer is -504.
Example 3
n = 1999999998return = 8999999991The reversed digits give 8999999991. That is larger than the biggest 32-bit integer (2147483647), which is why the answer is a 64-bit integer.
Constraints
-2^31 <= n <= 2^31 - 1
More DocuSign Online Assessment questions
- Max Sum With No Two Adjacent PicksOA · Seen Apr 2026
- Max Sum With No Two Adjacent Picks on a CircleOA · Seen Apr 2026
- Beautiful Number OrderingsOA · Seen Feb 2026
- Grid Path With the Most ClearanceOA · Seen May 2025
- Vehicle Mixes for a Wheel TotalOA · Seen May 2025
- Count Sales Rung Up at the Wrong PriceOA · Seen Feb 2021
- Most Disjoint Intervals From Starts and DurationsOA · Seen Feb 2021
- Fewest Fountains to Water the GardenOA · Seen Feb 2021
- Lowest Start That Keeps Running Totals PositiveOA · Seen Feb 2021
- Fewest Student Groups Within a Level GapOA · Seen Nov 2020
Similar questions at other companies
- Count Valid Square PairsAuxoAI · OA
- Counting Cows by Their LegsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Server InvestmentRippling · OARippling interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Identification Number Check DigitAbridge · OAAbridge interview questions
- Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Digit-Sum Sequence Join PointOpenAI · OAOpenAI interview questions
- Minimum Testers to Find the Poisoned BottleWalleye Capital · OA
- Address on Same PageNVIDIA · OANVIDIA interview questions