Parse a Signed 32-Bit Integer with Overflow Detection
Updated
Problem statement
Given a nonempty decimal string s, parse it as a signed 32-bit integer.
The string may begin with one optional + or - sign, followed by one or more decimal digits. It contains no spaces or other characters. Return the parsed integer written in plain decimal, with no plus sign and no leading zeros. If the value is outside [-2147483648, 2147483647], return "OVERFLOW".
Function
parseInt32(s: String) → StringExamples
Example 1
s = "-2147483648"return = "-2147483648"The value equals the minimum signed 32-bit integer and is valid.
Example 2
s = "9999999999"return = "OVERFLOW"The value exceeds the signed 32-bit maximum, so the answer is OVERFLOW.
Constraints
1 <= s.length <= 100000- After an optional leading sign, every character is a decimal digit.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
- Iterate Canonical IPv6 AddressesOpenAI · ONSITE INTERVIEWOpenAI interview questions
- Nth Staged License PlateGoogle · ONSITE INTERVIEWGoogle interview questions
- Bit at an Index After Repeated Binary ExpansionAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
- Fraction to Recurring DecimalGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Rank Bipedal Dinosaurs by SpeedMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Every Result of Grouping an ExpressionC3.ai · ONSITE INTERVIEWC3.ai interview questions
- Largest Minus Smallest Value of a Parenthesized ExpressionNutanix · ONSITE INTERVIEWNutanix interview questions
- String to Integer with ClampingAMD · ONSITE INTERVIEWAMD interview questions