FastPrepParse a Signed 32-Bit Integer with Overflow Detection
Problems/Parse a Signed 32-Bit Integer with Overflow Detection

Parse a Signed 32-Bit Integer with Overflow Detection

Microsoft logoMicrosoft● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Data Scientist internship report asks for turning a string into an integer while detecting overflow, and names 9999999999 as an example of overflow. We chose the decimal format, the signed 32-bit range, and a token OVERFLOW that you return.

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) → String

Examples

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

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String parseInt32(String s) {
      // Write your code here.
    }

}
Checking account…