CloudEndure interview question

parse number from string without using the language parsing technologies

Interview Answers

Anonymous

Jul 28, 2019

The main idea is to parse each digit of the string (starting from the least significant one) to a number, multiply the result by ten and add the digit. If the char is not a digit return or throw an error;

Anonymous

Jul 31, 2020

1. After checking for null or blank string, 2. initialize a "sum" variable to 0 3. ...and iterate over all digits from right to left - with each iteration add str[i] * 10^i to sum. 4. done