Make up your mind interviewbit!


#1

1.Your submission failed for the following input:

A : "O 2444X03537427 436K 7 09 19 31239778M 44 5874H5334439551540405 54797Q5 66U 89910W7162 9 003Y"

The expected returned value :

0

2.Your submission failed for the following input:

A : "-6435D56183011M11 648G1 903778065 762 75316456373673B5 334 19885 90668 8 98K X277 9846"

The expected returned value :

-6435

Aren’t these 2 cases conflicting?


#2

No they are not conflicting
In the first case you return the default value 0 when found no digit in the 0th index
In the second case you find a negative number starting from the 0th index so you return that


#3

If you look carefully at the 0th index, its an ‘O’ not a ‘0’.


#4

No in the first case you encounter junk value “O” before a number so you return zero(0). In second you encounter a full negative number before any junk.
The non junk values are numeric, ‘+’, ‘-’ and white space.
Also returns 0 in cases like"++2"
Hope this helps!