What is SIGSEGV help me out…
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: https://www.codechef.com/viewsolution/15830879
Hope this helped.
The query is already answered . Moreover I would advise you to use char array instead of string .
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 !!!
You are correct. And it’s easy to verify: link.