Why my code is giving segmentation fault on submitting ?

Link to the code
link text

link to the questionlink text

GOTCHA: In your code this block
if(str[i]==’}’)
{
//cout<<“1Hi\n”;
a=v[v.size()-1];
if(a!=’{’)
{
temp=1;
break;
}
else
{
if(a==’{’ && v.size()>=1) v.pop_back();
}
}
is producing segmentation fault because if(v.size()=0) then a=v[v.size()-1] becomes a=v[-1] which is invalid. Your logic is correct but gives seg fault for some inputs