FastPrepString to Integer (atoi)
Problems/String to Integer (atoi)

String to Integer (atoi)

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source asks you to implement atoi and gives one direct example, “123” to 123. We added the usual rules for spaces, signs, prefixes, bad input and overflow, plus input limits. Our version is about 68% the same as the reported question.

Convert s to a signed 32-bit integer.

  1. Skip leading ASCII space characters.
  2. Read one optional + or - sign.
  3. Consume the longest following prefix of decimal digits. If no digit is consumed, return 0.
  4. Ignore every character after that digit prefix.
  5. Clamp a value below -2^31 to -2^31 and a value above 2^31 - 1 to 2^31 - 1.

Function

stringToInteger(s: String) → int

Examples

Example 1

s = "123"return = 123

All characters belong to the decimal digit prefix.

Example 2

s = "   -042xyz"return = -42

Leading spaces and the negative sign are consumed. Parsing stops before x.

Example 3

s = "91283472332"return = 2147483647

The parsed positive value exceeds the signed 32-bit maximum and is clamped.

Constraints

  • 0 <= s.length <= 200.
  • s may contain ASCII letters, digits, spaces, signs, and punctuation.

More Bloomberg LP Phone Screen questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE 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

Similar questions at other companies

  • Dasher Pay with Store Waits and Peak HoursDoorDash · PHONE SCREENDoorDash interview questions
  • Ordered IP FirewallDatabricks · PHONE SCREENDatabricks interview questions
  • Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Minimum Number of Frogs CroakingCerebras · PHONE SCREEN
  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Read Across Sound TracksAirbnb · PHONE SCREENAirbnb interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions

Interview reports that mention this question

  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
  • Bloomberg New Grad SWE Offer Loops: 14 Experiences (Part 2 of 5)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int stringToInteger(String s) {
        // Write your code here.
    }

}
Checking account…