Segmentation fault occuring

please help me in spotting the reason for segmentation fault.
this is the link to my code:

Hey @Akshita99
You need to initialisethe vector while declaring.
The line ans.push_back(ans[k-1]);
and ans[k].push_back(a[j]);
and ans[k].pop_back();
are giving errors, this is because ans[k-1] and ans[k] have garbage values. if you initialise the vector while declaring as:
vector<vector > ans(no_of_rows, vector(no_of_cols, 0));
then you won’t get segmentation error.

the segmentation fault is removed now but the values are not getting push backed into the vector. It is giving 0 only as output

i tried to pass it by reference and it again gave segmentation fault

Hey @Akshita99
initialize the vector and pass it by referrence, it won’t give segmentation fault, also, check if there is some index out of bounds error in the vector, so take the correct size of the vector

I’m still not able to find the error. Please check it once. https://ide.codingblocks.com/s/207484

mam now there are no errors but none of the testcases is running

mam its done, i found the error

1 Like

@Akshita99
That’s awesome! Also, pls mark the doubt as resolved if you don’t have any further queries.