Back to problems

Production-Ready atoi for an Arbitrary Base

Algorithm · Microsoft · Medium

Write a production-quality function parseInt(s, base) that converts the string s into a 32-bit signed integer, interpreting its digits in the given base. Rules for the conversion: base is always between 2 and 36, inclusive. Any whitespace at the start of s is skipped. After the whitespace, there may be a single leading + or - sign. The characters 0 to 9 stand for the values 0 to 9. The letters A to Z, in either upper or lower case, stand for the values 10 to 35. Read digits…

Loading the rest of the question…