Integer to String Without Built-ins
Updated
Problem statement
Implement itoa. You are given a signed 32-bit integer num. Return its base-10 string.
- A negative number starts with
-. - The number
0gives"0".
Do not use built-in functions that turn a number into a string, such as str in Python or Integer.toString in Java. The goal of this exercise is to build the digits yourself. The tests cannot check this rule, but it is the point of the problem.
For example, num = 42 gives "42", and num = -17 gives "-17".
Function
intToString(num: int) → StringExamples
Example 1
num = 42return = "42"The digits of 42 are 4 and 2. The number is not negative, so the string is "42".
Example 2
num = -17return = "-17"The number is negative, so the string starts with -. The digits of 17 are 1 and 7. The string is "-17".
Example 3
num = -2147483648return = "-2147483648"This is the smallest 32-bit integer. It is negative, so the string starts with -, followed by the ten digits 2147483648. Be careful when you flip the sign: 2147483648 does not fit in a 32-bit integer. The string is "-2147483648".
Constraints
numis a signed 32-bit integer:-2^31 <= num <= 2^31 - 1
More Hudson River Trading Phone Screen questions
- Format a Signed Integer with CommasPHONE SCREEN · Seen Nov 2026
- Order and Batch Open-Close LifecyclePHONE SCREEN · Seen Nov 2026
- Tilting Maze BallPHONE SCREEN · Seen Oct 2026
- Tiered Expiring Item StorePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Mean vs Median: Chance of Missing the CenterPHONE SCREEN · Seen Sep 2026
- Market Data Signal WatcherPHONE SCREEN · Seen Jul 2026
- Contact Tracing Through Timed MeetingsPHONE SCREEN · Seen Nov 2024
- Polydivisible Pandigital NumbersPHONE SCREEN · Seen Feb 2024
- Defragment a Buffer of ObjectsPHONE SCREEN · Seen Nov 2023
- Expected People Met Before Someone TallerPHONE SCREEN · Seen Nov 2023
Similar questions at other companies
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
- 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
- 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
- Add Two Integers Given as StringsJane Street · PHONE SCREENJane Street interview questions
- Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
- Excel Sheet Column TitleUiPath · PHONE SCREEN