What is SIGSEGV help me out…


1 Like

@root00198 you are not checking the case when the length of the string is less than 3, in that case, your solution will give runtime error.
To know more about the status codes check here.

1 Like

The type that s.length() returned when converted to “long” changed into something else(I dont know why, maybe it returns unsigned long). So, when a string of length 1 was given, 1-2 = -1 and in unsigned type it changed into MAX-1 and it ran until that value ultimately getting out of bounds of the string. I typecasted s.length() to “int” and it worked perfectly fine.

Your AC code:

Hope this helped. :slight_smile:


The query is already answered . Moreover I would advise you to use char array instead of string .

You are correct. And it’s easy to verify: link.

1 Like

…But why?

1 Like

The error you are geting is because you are missing a case when string length <3
in that case your solution stumbles and faces runtime error !!!