Reported September 2026
Microsoftstring

Parse a Signed Integer in Any Base

Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Microsoft OA. Under 2s to a working solution.
Founder's read

The Microsoft OA reported in September 2026 looks like a warm-up: parse a string into a signed 64-bit integer in any base from 2 to 36. It's not a warm-up. The edge case that breaks a naive solution is the range check, because -9223372036854775808 is valid and 9223372036854775808 isn't. This is a string parsing problem with careful overflow handling, and every INVALID branch is a place to lose points. If you blank on the boundary logic during the live OA, StealthCoder sits invisibly on your screen as a safety net and hands you a working parser.

The problem

Parse text as a signed 64-bit integer in base, where the base is from 2 through 36.
Ignore leading and trailing ASCII whitespace. An optional leading + or - is allowed. Digits 0-9 represent values 0-9 and letters a-z or A-Z represent 10-35. Return the canonical decimal string, or INVALID when the base, syntax, digit, or signed 64-bit range is invalid.

Function
parseIntegerInBase(text: String, base: int) → String

Examples
Example 1
text = " -7f "
base = 16
return = "-127"
7f is 127 in base 16 and the sign makes it negative.
Example 2
text = "101"
base = 2
return = "5"
Binary 101 equals decimal 5.
Example 3
text = "8000000000000000"
base = 16
return = "INVALID"
The positive value exceeds signed 64-bit range.

Constraints
0 <= text.length <= 200.
0 <= base <= 40; values outside 2 through 36 are invalid.
Whitespace is ASCII space, tab, carriage return, or newline.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to accumulate the magnitude without ever overflowing your own integer type. Trim ASCII whitespace (space, tab, CR, LF), check the base is 2 to 36, read an optional sign, then require at least one digit. Map each character to 0-35 and reject any digit value >= base. Before each step, check magnitude * base + digit against the limit: 2^63 - 1 for positive, 2^63 for negative. In languages with 64-bit ints, use unsigned 64-bit or compare against limit / base first. Python or Java BigInteger makes it trivial but check what's allowed. Pitfalls: empty string after trimming, a lone sign like

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Parse a Signed Integer in Any Base cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as string to integer atoi. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Microsoft's OA.

Microsoft reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Parse a Signed Integer in Any Base FAQ

What's the trick in the Microsoft signed integer parsing problem?+

Handle overflow before it happens. Track the magnitude and compare against 2^63 - 1 for positive or 2^63 for negative. The negative limit is one larger than the positive one, and that asymmetry is what most naive solutions get wrong.

Which inputs should return INVALID?+

A base outside 2 through 36, an empty or whitespace-only string, a sign with no digits, any character that isn't alphanumeric, any digit whose value is at or above the base, and any result outside the signed 64-bit range.

Is -9223372036854775808 valid?+

Yes. It's the minimum signed 64-bit value. Its magnitude, 9223372036854775808, is one more than the positive max, so you must allow that magnitude only when the sign is negative. Positive 9223372036854775808 is INVALID.

How should I handle whitespace and case?+

Trim only space, tab, carriage return, and newline from both ends. Whitespace inside the number makes it invalid. Letters are case-insensitive, so 'f' and 'F' both equal 15. Convert with a small helper and reject everything else.

How do I prepare for this in 48 hours?+

Write the parser once from scratch, then test it against edge cases: empty string, lone '+', base 1, base 37, '-0', max and min 64-bit values, and one digit past each. Those cases cover nearly every way this problem gets failed.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Microsoft.

OA at Microsoft?
Invisible during screen share
Get it