[Discuss] STRING TO INTEGER (ATOI)

Hey folks,
Let’s discuss anything related to the STRING TO INTEGER (ATOI) problem in this thread

Can we use Integer class’s methods in this problem or do we need to do it in algorithmic way

can anyone help me i tried my best but always i failed in edge-test-2. Please help me

please give some hint to passed edge-case -2

Have you checked for all corner cases like given string can be other than 0-9, -, + and also what u r returning from the function if the string length is empty.
Hope this helps you :slight_smile:

It is simple math similar to reversing a number.
A single for loop is enough.


please give me a test case where it is failing it will be great help
thank you in advance

Bro I can’t reveal that but I can give u hint.
And the hint to return a default value when the input does not contain any kind of integers.

1 Like

base-test-1 is failing
anyone please help

Here too Base-Test-1 is failing. @Kiran Please Help!. Could not figure out even after 21 Build Failure.

Make sure you are handling things like :
Trimming off leading and trailing spaces.
Empty strings.
Negative or positive signs.
Non-numeric characters.

check for non-numeric characters

Hint for test cases: Make sure your code strips leading and trailing spaces. Make sure you handle the + or - at the beginning.
E.g." +283 "

did that still edge test case 2 is failing

Can you list some of the examples you tried?

Only getting the edge case 3 wrong.
Any idea what I might be missing?

Is there any case where ’ ’ or ‘+’ or ‘-’ lies in between the numbers?

Please reply, I need to complete these problems today.

Check your program whether it handles empty string.

No, there will be no such characters between the digits. Space can be at beginning or end. + or - can be at the beginning of the number.