Things to consider before submitting


#1

Do check
a) If your code responds correctly to the signs.
+7 -----> 7
-7 -----> -7
-+7 -----> 0

b) Check for other characters
m7 -----> 0
7m -----> 7
"7 ----> 0
7; -----> 7

c) Do check for the leading whitespaces, ignore them and store the number, after storing a number, if a whitespace (or any other character) is encountered, then stop storing further.

d) Check the overflow condition
12345678918 -----> 2147483647
-12345678918 -----> -2147483648


#2

Thanks a lot! Helped to figure out all the edge cases!


#3

Thanks man this helped me much especiallay that m7 case
Well done !! Appreciate your effort


#4

Thanks, also if you’re using C++ , you should know that after both type of overflow, value of integer turns INT_MIN, if only I knew this, wouldn’t had to waste 1:30+hrs.


#5

Take ans as long long

int isNegative = false;
long long ans=0;

compare in each iteration

if(ans > INT_MAX){
if(isNegative)
return INT_MIN;
return INT_MAX;
}