How to remove SIGSEGV runtime error . Please help

Problem code- ITGUY15
This code is working everywhere but codechef is showing runtime error and I am not able to find the reason for this so please help.
using namespace std;

void recur(string s)


vector <char> v;

int flag=0;

for(int i=0;i<s.length();i++)


vector<char>::iterator it1,it2;


for(int i=0;i<v.size();i++)












string str="";

 for(int i=0;i<v.size();i++)




int main()


int t;




   string s;




return 0;        


In the above line of code , you are accessing out of bound memory address for vector when i=v.size()-1 and v.size()-2 as v.size()-1+1=v.size(), which is out if bound .
To remove SIGSEGV you can push back any two random letter in the vector other than a,b,c

1 Like

Can you tell me something regarding
What steps did you follow from starting competitive coding to till now to get such higher rating and maintaining it so well
You are genius
:pray: Plz reply that help me to get some idea what path should I follow to become such a good like you or even some close to you

1 Like

I am not . I think I reached 5 star by luck .
I refered to CP algorithms, and youtube channel named Code NCode for learning Algos . Solved problems on these Algos on some sites.Though Now a days , Questions related to Algos have decreased in CP , but still I think you will have to learn some important CP Algos . But do give contest regularly atleast on one platform, Because now a days most of the CP contests question are logic based

1 Like

@dhruv788 I did the same what you told and also another approach was that I ran the loop of i till v.size()-3 i.e i+2<v.size() so that it does not go out of bound. But it is still showing runtime error. Is there any other way or can you once try it yourself and tell.

Can you link the submission

then check

these are the two approaches.

The runtime error(SIGSEGV) is caused due to the line 20 . There you are continuously doing it1+=i
Whereas I think either you should it1++ before the if statement or inside if statement make it1=v.begin() and then do it1+=i
Refer the correction I did below

Yes it worked. Thank you so much!!